• Post Reply Bookmark Topic Watch Topic
  • New Topic

Binary String to Hexadecimal value problem  RSS feed

 
J amodi
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I need to convert binary string (e.g 01110111) to hexadecimal value.

If I am using this code


then it is getting rid of initial 0s After converting in integer. above code will output me only "f" instead of "0f". Could anyone help me to resolve this issue ?

 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You already have one thread that seems to be the same as this one. Please UseOneThreadPerQuestion.(⇐click)
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a String.format() function, which takes a format string and a parameter (or parameters) and can be used to output formatted strings. The format string allows you to specify flags to modify the output of the method. I suppose you could put this method to good use, just look it up in the documentation.
 
Mohamed Sanaulla
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Verdegan wrote:You already have one thread that seems to be the same as this one. Please UseOneThreadPerQuestion.(⇐click)

Is this the thread you were referring to? I am not sure if they are similar, as the other thread was converting Binary value to ASCII.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohamed Sanaulla wrote:
Jeff Verdegan wrote:You already have one thread that seems to be the same as this one. Please UseOneThreadPerQuestion.(⇐click)

Is this the thread you were referring to? I am not sure if they are similar, as the other thread was converting Binary value to ASCII.


Yeah, that's the one. I guess I was confused.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!