| Author |
String to Binary to Integer
|
Brendan Crisler
Greenhorn
Joined: Feb 07, 2007
Posts: 19
|
|
This may sound stupid, but I am needing help parsing out a 168-bit "binary" stirng (it's a string, but it's just 0s and 1s). What I need to do is parse out certain portions of the string (using substring), and from those substrings, get an integer equivalent. Example: /***** String a = testData.substring(8, 38); // a = 001110101011000011010111011000 *****/ I want to convert 'a' to integer. Any help is appreciated. Thanks, B
|
 |
Bennett Rainville
Greenhorn
Joined: Feb 16, 2007
Posts: 5
|
|
|
I don't know of anything in the java library that will do this for you, but if you'd like to try an implement a solution yourself this would be a good place to start.
|
 |
Garrett Rowe
Ranch Hand
Joined: Jan 17, 2006
Posts: 1295
|
|
Integer.parseInt(String ,int) does just what you want:
|
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
|
 |
Brendan Crisler
Greenhorn
Joined: Feb 07, 2007
Posts: 19
|
|
Thanks. That's what I had done. Took me a while to realize it, and as soon as I did, I came here and saw the same things I had just done. Thanks again.
|
 |
Oliver Kamps
Greenhorn
Joined: May 15, 2007
Posts: 18
|
|
Hi, since you have to handle 168 bits try java.math.BigInteger.BigInteger(String, int). Cheers, Oliver
|
 |
 |
|
|
subject: String to Binary to Integer
|
|
|