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.

You know that each position in a decimal number means a power of 10. Starting from the right, moving to the left, we have the number of ones, then the number of tens, then the number of hundreds, thousands, ten-thousands, and so on. So 4242 is 2 ones plus 4 tens plus 2 hundreds and 4 thousands. That is: 2 + 40 + 200 + 4000, resulting in, yes, 4242. 10 is the base of this decimal system

Hexadecimal has base 16, and octal has base 8.

In a hexadecimal number, going from right to left, you have the number of ones, the number of sixteens, the number of two-hundred-and-fifty-sixes, the number of four-thousand-and-ninety-sixes, and so on. So 0x65 means 5 ones plus 6 sixteens, that is, 5 plus, um..., 96. That makes 101 in decimal. So 0x65 (read it as 65 in hex) is 101 in decimal.

I leave the octal conversion as an exercise. Do not forget that an int literal begining with 0 is octal.

Any modern (high-)school maths book should have a few pages on this topic.

[ September 17, 2005: Message edited by: Barry Gaunt ]

six times sixteen is nintysix not eighty

[ September 17, 2005: Message edited by: Barry Gaunt ] [ September 17, 2005: Message edited by: Barry Gaunt ]

convert the number to binary first each hexa digit can be represented by four binary bits eg 6==0110,f=1111and 0=0000

once you have done this conversion to decimal will be a piece of cake as you can conver the decimal to binary eg 111 = 1*2^0 + 1*2^1 + 1*2^2 == 7 pls note the ^ stands for power and not XOR

Regards Simon

Roy Simon
Ranch Hand

Joined: Aug 26, 2005
Posts: 62

posted

0

to convert to hexa or octal binary rep will work

as the radix for binary is 2 the radix of hexa 16(2^4)-hence each hexa digit can be rep as 4 binary digits the radix of octal is 8(2^3)-hence each octal bit can be rep as 3 binary bits