Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c - difficulties with bit operations

I'm debugging a program with GDB.

unsigned int example = ~0;

gives me:

(gdb) x/4bt example
0xffd99788:     10101000        10010111        11011001        11111111

why is this not all 1's? i defined it as ~0... then the next line of code is:

example>>=(31);

and GDB gives me this when I try to examine the memory at bits:

(gdb) x/4bt example
0xffffffff:     Cannot access memory at address 0xffffffff

what is going on???

like image 491
Tony Stark Avatar asked Dec 13 '22 22:12

Tony Stark


2 Answers

You need to take the address of example in the gdb statement:

(gdb) x/4bt &example
like image 168
Raul Agrait Avatar answered Dec 28 '22 12:12

Raul Agrait


I think that the x command examines memory, so example would be interpreted as pointer. Try

x/4bt &example

or simply

print /x example
like image 22
MartinStettner Avatar answered Dec 28 '22 10:12

MartinStettner