For Decimal to Hex, just divide successively by 16, keeping the whole number result but noting the remainder of each division as you go, until you get a 0 result. Take decimal 11948 11948 / 16 = 746 rem. 12 746 / 16 = 46 rem. 10 46 / 16 = 2 rem 14 2 / 16 = 0 rem 2 Then, go backwards through your list of remainders and convert each to hex. For this example, you will get 2EAC, which is the Hex representation of Decimal 11948 Same process when you convert Decimal to Octal, only your divisor will be 8. For Hex to Decimal: 2EAC = (2 * 16^3) + (14 * 16^2) + (10 * 16^1) + (12 * 16^0) = 11948 When converting from Octal, use powers of 8.
[This message has been edited by JUNILU LACAR (edited June 21, 2001).]
Hi Felix, Its easy, as long as you can perform a power function and some multiplication. Hex to Dec: Values 0 to 9 translate directly, A - F map to 10 to 15 Generic formula: Decimal subValue = Hex digit * (16 ^ digit position) where digit position starts at zero in the rightmost position and increments by one as you go left. Once you get all the subtotals then you just add them together. Examples: 0x4321 1*16^0 + 2*16^1 + 3*16^2 + 4*16^4 1*1 + 2*16 + 3*256 + 4*4096 1 + 32 + 768 + 16384 17185 0x7D 13*16^0 + 7*16^1 13*1 + 7*16 125 Oct to Dec: Use the same formula but you use 8 instead of 16. Values 0 - 7 translate directly
Hi Felix, I have some notes on binary,octal,decimal, hexidecimal conversions posted at http://www.janeg.ca/scjp/oper/binhex.html Hope they help. ------------------ Jane Griscti Sun Certified Programmer for the Java� 2 Platform