This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes int to hexadecimal Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "int to hexadecimal" Watch "int to hexadecimal" New topic
Author

int to hexadecimal

dale con
Ranch Hand

Joined: Apr 15, 2005
Posts: 93
Dear all

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

Many thanks
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Have a look at the static Integer.toHexString() method.


[Jess in Action][AskingGoodQuestions]
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

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.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: int to hexadecimal
 
Similar Threads
Hex in Eclipse Debugger
converting hexa decimal into int
double excepts hexadeci.?
Explaination for BITWISE OPERATIONS
How to convert Hexadecimal into int