• Post Reply Bookmark Topic Watch Topic
  • New Topic

leading zeros  RSS feed

 
Arjunkumar Shastry
Ranch Hand
Posts: 986
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When we use Integer.toBinaryString(11),it returns 1011.Method removes leading zeros if any.How to add these leading zeros if there are many integers to be converted to binary string?
 
Nigel Browne
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Arjunkumar Shastry:
When we use Integer.toBinaryString(11),it returns 1011.


1011 is the decimal number 11 converted to binary format. Please explain your problem using an example of where you think the output is incorrect.
 
Arjunkumar Shastry
Ranch Hand
Posts: 986
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of 1011,we want 001011.Thats in 6 bit format.
 
Steven Bell
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as I know you would have to do the padding yourself after you get the String representation.
 
Junilu Lacar
Sheriff
Posts: 11165
160
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Steven Bell:
As far as I know you would have to do the padding yourself after you get the String representation.


And before you go and write some code to do that, take a look at org.apache.commons.lang.StringUtils.leftPad()
 
Arjunkumar Shastry
Ranch Hand
Posts: 986
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.I know Jakarta commons.But I think I will do this small job myself.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!