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!

To determine the no. of leading 0's in an int

807605Sep 11 2007 — edited Sep 11 2007
Hi,

I'm trying to determine the no. of leading 0's in an int.

I have something like:
int num = 000012345;
And for this i want the result to be 4.

Is there a way for me to achive this without actually converting my int into a String ? Pls advice.

Note:
I tried using Integer.numberOfLeadingZeros(). But i'm getting the result as 19. I think it is taking the number in octal and returning the leading 0 bits count. Not sure.

Also, i think in the firts place, the 0's in the number are not at all being stored. Is there a way so that i can force storage of leading 0's ?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 9 2007
Added on Sep 11 2007
9 comments
1,396 views