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() I need Bloody Leading Zeros

807597Sep 30 2005 — edited Sep 30 2005
Hello All,

I am doing the following:
public String stringToBinary(String input) {
                     int intRepresentation = Integer.parseInt(input, 16);
                     String binaryString = Integer.toBinaryString(intRepresentation);
                     return(binaryString);
 }
I need the leading zeros though for my project, they are crucial. For example for the input:

'03' I need the function to return '00000011' not '11' like it does currently.

Another example, if input was '36' then I need it to return '0011 0110'.

Thanks guys!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 28 2005
Added on Sep 30 2005
6 comments
563 views