Convert byte in hex to decimal question

Viewing 2 reply threads
  • Author
    • #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
      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)
      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

      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 🙂

    • #54215
      Don Donzal

      Thanks for following up with the answer.


Viewing 2 reply threads
  • You must be logged in to reply to this topic.

Copyright ©2021 Caendra, Inc.

Contact Us

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


Sign in with Caendra

Forgot password?Sign up

Forgot your details?