-
get binary value
Hi all
Consider that I have a string in hex like this:
Now I wanna convert it to binary, then I wanna have each digit single. For example, binary value for above string is:
Code:
11000000100000000001011000000000100000110000000000000000000100
And I wanna have
Code:
1
1
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
1
0
1
1
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
How can I achieve this?
-
You can use:
Code:
// Long: static long parseLong(String s, int radix)
long l = Long.parseLong("3020058020C00004", 16);
// Long: static String toBinaryString(long i)
String b = Long.toBinaryString(l);
// String: char charAt(int index)
for (int i = 0; i < b.length(); i++)
{
System.out.println(b.charAt(i));
}
to parse the input String to a long and then to transform it into a binary string. In th end you display the digits one by one.
-
cross-posted in the Sun Java forums.