Need elegant way to cast four bytes into a long

Skip Montanaro skip at pobox.com
Sat Aug 9 13:06:57 EDT 2003


    >> You mean like this:
    >> 
    >> l = long(a[0] + a[1] << 8 + a[2] << 16 + a[3] << 24)
    >> 
    John> Bzzzzzt. Oh the joys of operator precedence! 

Yeah, I realized that after seeing a couple other responses.  Should have
kept my mouth shut.  I tend to think of << and >> as X2 and /2 operators and
thus mentally lump them together with * / and %.  Fortunately, I don't do
much bit twiddling or I'd be in real trouble...

Skip





More information about the Python-list mailing list