Skip to Main Content

New to Java

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!

Integer.toBinaryString() - 4 bits every time

807601Mar 3 2008 — edited Mar 3 2008
Hello,

I am using the Integer.toBinaryString() method to convert ints between 1 and 14 into binary.I would like them to be 4 bits long every time, i.e 2 = 0010. At the moment a 2 would be represented as 10. I need them as 4 bits because i will be concatenating 6 of these binary strings together, and losing length will completely mess up the final binary string.

Thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 31 2008
Added on Mar 3 2008
5 comments
695 views