On Fri, 6 Jul 2007, Jerry Hill wrote: > In your formula ( (176 & 127) * 256 + 192 ) you're only using 7 bits > of your high byte. Why are you masking off that last bit?
I know in MP3 files, some of the ID3 lengths are coded this way, i.e. as a four-byte field, each byte of which has the high-order bit set to zero, and the other seven bits significant, for a total of a 28-bit integer. For example, 0x00000101 would equal 129 (not 257, as one would expect). Scrounging through some old code, I used to use this to pull out the length: def ID3TagLength(s): """ Given a 4-byte string s, decode as ID3 tag length """ return (ord(s[0]) * 0x200000 + ord(s[1]) * 0x4000 + ord(s[2]) * 0x80 + ord(s[3]) ) _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor