Search code examples
cbinarybooleanhex

Adding one byte to a hexadecimal number


I seem to have confused myself so much that this doesn't make sense anymore.

1 byte = 8 bits.

So if I have a memory location such as

0xdeadbeef
3735928559 (base10)
1101 1110 1010 1101 1011 1110 1110 1111

Now if I add one byte to 0xdeadbeef, what is the binary sequence I'm adding? Is it 1000? If I add 1 bit, I get 0xdeadbee0, and if I add 1 bit 8 times, I get 0xdeadbef7. Which is correct?

I remember from microprocessors the counter incremented in PC += 4, which gives 0xdeadbef3, so I'm not sure which is the right answer.


Solution

  • What I understand from your question is that, you are confused with adding a bit and a byte to the counter.
    Since memory addresses are measured in bytes (in programming languages), any arithmetic operation to it is done in bytes.
    To increment counter, adding 1 to it is like increment it to one byte next to the base address. Adding 1 to 0xdeadbeef will increment it to 0xdeadbef0.