Daveid Fred
Daveid Fred

Reputation: 419

Converting memory addresses

I have been searching around for this question but cant seem to find it. If I am in GDB disassembling code, how do I convert something like 0xfffffff4 to -0xc (i found the values online)

I am trying to implement how its done in Perl. I was using hex, but I have no idea what im doing:

print hex(shift);

Upvotes: 0

Views: 145

Answers (2)

wallyk
wallyk

Reputation: 57774

In a 32-bit register or memory access, 0xfffffff4 is -0xc (or -12)—assuming a modern CPU architecture, all of which use twos-complement.

Upvotes: 1

Jay
Jay

Reputation: 1003

it's two's complement http://en.wikipedia.org/wiki/Two%27s_complement

So, what you do is invert every bit, and then add 1.

For example 0xffffff04 would become 0x000000fb+1=0x000000fc

EDIT: and to change it back, you do the same thing: so 0x000000fc would become 0xffffff03+1=0xffffff04

Upvotes: 1

Related Questions