# Convert byte in hex to decimal question

• Author
Posts
• #8830

Hi there,

I’m studying the Art Of Exploitation book, and in it there is an example on converting the hex representation of the bytes to decimal, and how an incorrect byte ordering affects the end result:

``````
(gdb) x/4xb \$eip
0x8048384 : 0xc7 0x45 0xfc 0x00
(gdb) x/4ub \$eip
0x8048384 : 199 69 252 0
(gdb) x/1xw \$eip
0x8048384 : 0x00fc45c7
(gdb) x/1uw \$eip
0x8048384 : 16532935
(gdb) quit
The program is running. Exit anyway? (y or n) y
199*(256^3) + 69*(256^2) + 252*(256^1) + 0*(256^0)
3343252480
0*(256^3) + 252*(256^2) + 69*(256^1) + 199*(256^0)
16532935
quit
``````

What I don’t understand is, why he multiplies the decimal value with 256? I have tried to Google this a lot and read a lot of tutorials on decimal and hex conversion, but I still find it hard to grasp.

My “theory” so far is, that “multiply by 256” is something to do with the fact that a byte can be represented by two hex digits, where each hex digit can have 16 different values, and because the decimal value is derived based on two hex digits we need to do 16^2 = 256 and multiply the decimal to 256 to the power of it’s weight.

But to be honest I’m confused and don’t really understand what is going on ???

I feel a bit stupid for asking such a “basic” question, and hopefully it’s not the wrong place to ask.

It would be really nice if someone could explain this to me 🙂

• #54214

Ah I finally figured it out! For anyone that would be interested, it finally ‘clicked’ after reading the following:

http://cs.stackexchange.com/questions/32392/why-can-the-alphabet-be-represented-in-numbers-in-base-256

Now the answer seems so obvious 🙂

• #54215

Thanks for following up with the answer.

Don