# computer science lab tips

Discussion in 'OT Technology' started by nur23, Feb 12, 2007.

1. ### nur23OT Supporter

Joined:
Jun 7, 2006
Messages:
487
0
Location:
Chi-Town
For my computer science labe are required to convert from hexidecimal (base 16) to base 2.

Can someone help me by telling me how i should begin? I sure it starts with some kind of loop, but from then on i'm stumped.

Code:
```// Lab16st.java
// The Number System Converter
// Student Version

import java.util.Scanner;
public class Lab16st
{
public static void main (String args[])
{
System.out.println("Lab 16 - Number Conversion Program\n\n");

// The next 2 lines are used in all versions.
System.out.println("ABCD1234 Base-16 converts to " + BaseConverter.fromHexToBin("ABCD1234") + " in Base-2.\n");
System.out.println("E12B47F5 Base-16 converts to " + BaseConverter.fromHexToBin("E12B47F5") + " in Base-2.\n");

// The next 2 lines are used in the 90-point versions and above.
// System.out.println("1011111011101111 Base-2 converts to " + BaseConverter.fromBinToDec("1011111011101111") + " in Base-10.\n");
// System.out.println("11100100100110110 Base-2 converts to " + BaseConverter.fromBinToDec("11100100100110110") + " in Base-10.\n");
// The next line is used in the 95-point versions and above.
// System.out.println("1011111011101111 Base-2 converts to " + BaseConverter.fromBinToHex("1011111011101111") + " in Base-16.\n");
// The next line is used in the 100-point versions and above.
// System.out.println("11100100100110110 Base-2 converts to " + BaseConverter.fromBinToHex("11100100100110110") + " in Base-16.\n");

// The next 3 lines are used in the 105 and 110-point versions.
// System.out.println("1000 Base-10 converts to " + BaseConverter.fromDecToAny(1000,5) + " in Base-5.\n");
// System.out.println("1000 Base-10 converts to " + BaseConverter.fromDecToAny(1000,8) + " in Base-8.\n");
// System.out.println("200 Base-10 converts to " + BaseConverter.fromDecToAny(200,2) + " in Base-2.\n");

// This last line is only used in the 110 point version.
// System.out.println("48879 Base-10 converts to " + BaseConverter.fromDecToAny(48879,16) + " in Base-16.\n");
}
}

class BaseConverter
{
public static String fromHexToBin(String hexNum)
{
String binNum = "";

return binNum;
}
```

2. ### deusexaetheraOT Supporter

Joined:
Jan 27, 2005
Messages:
19,696
1
We don't do homework here.

That said, you can convert from base 16 to base 2 by separating each digit and multiplying it by the appropriate power of 16^x, adding all of the products together, then dividing by powers of 2^x to extract the binary digits.

Joined:
Nov 13, 2001
Messages:
11,861
0
Location:
4. ### nur23OT Supporter

Joined:
Jun 7, 2006
Messages:
487
0
Location:
Chi-Town
I'm not asking you to do my homework. What i am asking is for some help since i don't know how to start.

You could at least offer some help.

To cyber: Google is very inaccurate in terms of finding java coding that must fit the specific requirements of this lab. If there is such a website that offers the help i'm siking, i would gladly follow any links you guys post.

5. ### deusexaetheraOT Supporter

Joined:
Jan 27, 2005
Messages:
19,696
1
I did offer some help. I told you the algorithm you need to implement in order to convert hex to binary; in effect, I did the hard part for you.

6. ### nur23OT Supporter

Joined:
Jun 7, 2006
Messages:
487
0
Location:
Chi-Town
I understand what you said, yet it will be if no use if i can't put it in terms of coding.

Will the conversion be sent through a loop? Also, how do i convert characters into integer form, that will be expressed in a base 2 format?

7. ### CoottieBOOMER......SOONEROT Supporter

Joined:
Jun 6, 2006
Messages:
32,364
0
Location:
OKC
So you can't google like this:
java convert char to int

Ok...I'll try it...let's see what we get:

Dude google is not unreliable...you simply need to learn to search

Joined:
Jan 16, 2003
Messages:
10,761
3
Location:
Plantation, FL
youre not a CS major are you?

9. ### Sexual VanillaNew Member

Joined:
May 23, 2005
Messages:
6,305
0
Location:
South Carolina
I would hope not.

10. ### CorpOT Supporter

Joined:
Sep 11, 2003
Messages:
28,200
0
Location:
Providence, RI

Joined:
Jan 16, 2003
Messages:
10,761
3
Location:
Plantation, FL
yeah i was gonna say go ahead and drop the course and change majors if you are CS/CE but if you're like an IT major or something you could just grind this one course out.

Joined:
Jan 27, 2005
Messages:
19,696