jokoon
jokoon

Reputation: 6633

Why does python output negative hexadecimal?

http://docs.python.org/release/2.4.4/lib/typesseq-strings.html

The table says unsigned hexadecimal, my outputs are signed...

for a in words: # list of word
    print '%x'%hash(a)

also http://codepad.org/Cvd0Bg2T

Upvotes: 1

Views: 137

Answers (2)

Pierre Imbaud
Pierre Imbaud

Reputation: 21

The change appeared (or seemed to) in 2.6; in http://docs.python.org/release/2.5.4/lib/typesseq-strings.html, U find: ... x Unsigned hexadecimal (lowercase). in http://docs.python.org/release/2.6/library/stdtypes.html#string-formatting: ... 'x' Signed hexadecimal (lowercase).

Not a word about the change in 2.6 "whats new"

The new policy parts from the "printf" policy. while debuging C code, I used to have an ipython interpreter open, next to my gdb terminal, for address calculation. This doesnt work any more, and I find no easy turnaround.

Upvotes: 2

kenm
kenm

Reputation: 23945

That documentation is for Python 2.4. You're probably using a more recent version. Take a look at a newer version of that table - %x is signed now.

Upvotes: 4

Related Questions