# int to hexadecimal

dale con

Ranch Hand

Posts: 93

posted 10 years ago

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

To convert to octal, break the binary representation into blocks of

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

It is sorta covered in the JavaRanch Style Guide. |