Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

int to hexadecimal

 
dale con
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all

Can someone show me how to convert an int to a hexadecimal?

Many thanks
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at the static Integer.toHexString() method.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's one method...

Convert to binary, then convert each "block" of 4 binary bits to a hex digit.

For example, consider 179. In binary, this is 10110011. Break this into blocks of 4 from right to left (since there might be leading zeros): 1011 0011. Then convert each of these blocks to a hex digit: b3.

Note:
To convert to octal, break the binary representation into blocks of 3 (from right to left): 010 110 011. Then convert each of these blocks to an octal digit: 263.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic