Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Python int to hex string

Name: Anonymous 2007-12-24 2:58

class crc32calc:
    def __init__(self): self.value = 0
    def update(self, data): self.value = zlib.crc32(data, self.value)
    def digest(self): return self.value
    def hexdigest(self): return '%08x' % self.value

Trying to get result of crc32 sum in hex. '%08x', however, sometimes returns a negative value (negative sign followed by seven hex digits). How can I get the right value?

Name: Anonymous 2007-12-24 2:59

Hmm, I'm not sure. Try indenting more naturally.

Name: Anonymous 2007-12-24 3:36

You're getting the right value, you're interpreting it wrong.

tl;dr read SICP.

Name: Anonymous 2007-12-24 3:46

ONE WORD, THE FORCED NEGATION OF INDENTED INTEGERS, THREAD OVER.

Name: Anonymous 2007-12-24 4:04

print '%u %08x' % (self.value, self.value)

prints -145952065 -8b30d41
I'm looking for 4149015231 f74cf2bf
I assume self.value is being treated as a signed int. How do I get the unsigned value?

Name: Anonymous 2007-12-24 4:31

Is Python tail-recursive?

Name: Anonymous 2007-12-24 4:59

>>6
Ouroboros?

Name: Anonymous 2007-12-24 6:24

Use a version of Python lower than 2.4.

Name: Anonymous 2007-12-24 6:44

>>5
(2**32+self.value)%2**32

Name: Anonymous 2007-12-24 11:03

>>7
L*O*L

Name: Anonymous 2007-12-24 12:29

def hexdigest(self): return '%08x' % (self.value & 0xffffffff)

Name: Anonymous 2007-12-24 12:53

>>11
Ah, much better

Name: Anonymous 2009-03-06 13:05

zlib decompression and some bad luck could   land you a   SPACE TOAD Are.

Name: Anonymous 2010-11-25 8:33

Don't change these.
Name: Email:
Entire Thread Thread List