• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String to Binary to Integer

 
Brendan Crisler
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Integer.parseInt(String ,int) does just what you want:

 
Brendan Crisler
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

since you have to handle 168 bits try java.math.BigInteger.BigInteger(String, int).

Cheers,
Oliver
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic