Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Can I get the bit at specified index from a BigInteger

892826Mar 23 2012 — edited Mar 27 2012
Hi, I am adding two BigInteger each for a binary number in this manner-
//x and y are StringBuilder object having large binary number on each
BigInteger a = new BigInteger(x.toString(), 2);
BigInteger b = new BigInteger(y.toString(), 2);
BigInteger c = a.add(b);
Now i need to know the bit value of given index in BigInteger c. For that, I am converting c to binary string using c.toString(2); then i am using string.charAt(index); method. This looks pretty fine but the last BigInteger to binary conversion has not that much use because i just need to know the bit, not the whole binary number. This can improve the program. Is there any better way for achieving the same?
Thank you
This post has been answered by doremifasollatido on Mar 23 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 24 2012
Added on Mar 23 2012
8 comments
299 views