Question

I've got a value (call it address) which is a memory address and I am trying to figure out where it is pointing.

(pdb) p address
18446738026812173208L

With the help of a hex converter, I can find out that this is equal to 0x0AFEBFB4, but how do I force hex-formatted output from the debugger itself?

Was it helpful?

Solution

You can use hex, oct, bin and int functions:

In [8]: hex(18446738026812173208L)
Out[8]: '0xfffffa8018d46b98L'

In [9]: oct(18446738026812173208L)
Out[9]: '01777777650003065065630L'

In [10]: bin(18446738026812173208L)
Out[10]: '0b1111111111111111111110101000000000011000110101000110101110011000'

In [11]: int(bin(18446738026812173208L), 2)
Out[11]: 18446738026812173208L

In [12]: int(oct(18446738026812173208)[:-1], 8)
Out[12]: 18446738026812173208L

In [13]: int(hex(18446738026812173208)[:-1], 16)
Out[13]: 18446738026812173208L

The slicing is required as all three functions return a string and both oct and hex append L.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top