July 19, 2015 at 8:32 am #8830bahrParticipant
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
: 0xc7 0x45 0xfc 0x00
(gdb) x/4ub $eip
: 199 69 252 0
(gdb) x/1xw $eip
(gdb) x/1uw $eip
The program is running. Exit anyway? (y or n) y
reader@hacking:~/booksrc $ bc -ql
199*(256^3) + 69*(256^2) + 252*(256^1) + 0*(256^0)
0*(256^3) + 252*(256^2) + 69*(256^1) + 199*(256^0)
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 🙂
July 20, 2015 at 7:37 pm #54214bahrParticipant
Ah I finally figured it out! For anyone that would be interested, it finally ‘clicked’ after reading the following:
Now the answer seems so obvious 🙂
July 21, 2015 at 12:28 am #54215Don DonzalKeymaster
Thanks for following up with the answer.
You must be logged in to reply to this topic.