[Tutor] << operator ?

Prahlad Vaidyanathan slime@vsnl.net
Wed, 10 Apr 2002 23:31:14 -0400


[ Resending because the previous one didn't reach the list ]

Hi,

What does this "<<" operator do ? IIRC, it is a bit-wise shift operator,
but I don't know what that means either :-(

Actually, I didn't come across it till today, when I saw this piece of
code :

"""
class MP3Header:
    ....
    def read_byte(self, prev):
        nextbyte = self.fp.read(1)
        if nextbyte == "":
            return ""
        return (prev << 8) | ord(nextbyte)

    def find_marker(self):
        while 1 :
            data = (ord(self.fp.read(1)) << 8) | ord(self.fp.read(1))
            self.fp.seek(-1, 1)
            if data & 0xffe0 == 0xffe0 :
                self.fp.seek(-1, 1)
                return self.fp.tell()
        return 0
    ...
"""

This operator is used all over the place in this script, and I have no
idea what it does. Please enlighten me.

Thanks !

pv.
-- 
Prahlad Vaidyanathan  <http://www.symonds.net/~prahladv/>

Is it weird in here, or is it just me?
		-- Steven Wright