Convert byte in hex to decimal question

This topic contains 2 replies, has 2 voices, and was last updated by  Don Donzal 3 years, 11 months ago.

  • Author
    Posts
  • #8830
     bahr 
    Participant

    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
    reader@hacking:~/booksrc $ bc -ql
    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
    reader@hacking:~/booksrc $

    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
     bahr 
    Participant

    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
     Don Donzal 
    Keymaster

    Thanks for following up with the answer.

    Don

You must be logged in to reply to this topic.

Copyright ©2019 Caendra, Inc.

Contact Us

Thoughts, suggestions, issues? Send us an email, and we'll get back to you.

Sending

Sign in with Caendra

Forgot password?Sign up

Forgot your details?