PDA

View Full Version : Really having difficulty converting decimal to hexadecimal



yingxuan
04-11-2004, 11:59 AM
hello
I am stuck on a question

I have the number 2947 and need to convert to hexadecimal.
As far as I'm aware u divide 2947 by 16 as hexadecimal base is 16.

but as I keep dividng I notice that what I thought I am doing is wrong.
Could anybody please help me?

Murray P
04-11-2004, 12:06 PM
0123456789abcdef

2947 = 00000B83

Cheers Murray P

Spacemannz
04-11-2004, 12:06 PM
If u use XP its calculator if u view scientific will give u the answer.

B83 according to XP's calculator is 2947 Dec in HEX.

yingxuan
04-11-2004, 12:07 PM
Yeah I know but I wanna know the logic behind it.Working on how to actually get that answer

Murray P
04-11-2004, 12:13 PM
Readme (http://www.danbbs.dk/~erikoest/hex.htm) ;)

Cheers Murray P

yingxuan
04-11-2004, 12:17 PM
Ah thanks.!!i wanted to find a simple instruction page to work with!

yingxuan
04-11-2004, 12:34 PM
44978 /16= 2811

remainder is 2.
From that site below.Decimal to hexadecimal conversion.u divide the number by 16.

in this case 44978/ 16 is 2811

Why is the remainder 2?

Graham L
04-11-2004, 01:46 PM
The remainder is 2 because that's what left over when you do that division. :D 2811*16 --> 44976. 44978-44976-->2.

But.

You shouldn't be dividing 44978 by 16. You need to start with the biggest power of 16 which will fit. (I suspect the tutorial might have dealt only with small numbers. :_|

Decimal numbers have one column for each power of 10 : 10^0, 10^1, 10^2, 10^3 ... (from right to left).

Hex numbers use one column for each power of 16: 16^0, 16^1, 16^2, 16^3 ... (again from right to left).

the powers of 16 are: 1, 16, 256, 4096, 65536, ...

To convert 44986: 65536 is too big, so try 4096. That gives 10 (decimal !) so write down "A" in the first column. The remainder is 4026, so divide that by 256, make the answer into hex, and write that down. You have a remainder, again, so divide that by 16 for the penultimate digit. The remainder is less than 16 (by definition) so that's the last column.

yingxuan
04-11-2004, 02:25 PM
Thanks for that.My friend looked at it and explained what you just wrote to me!

Graham L
04-11-2004, 02:29 PM
And remember that if you skip a "powerof16", you neet to put a "0" in that column.

Graham L
04-11-2004, 03:01 PM
And for practice, try converting "decimal to decimal". The method is the same, whatever the base.