Let's take the Wikipedia example where they show Man being encoded:
Code:
In[0] In[1] In[2]
01001101.01100001.01101110
The bytes we are interested in, in the case of Out[2] are marked in red. We can break the line down in steps, making it easier to see what's going on.
Code:
Out[2] = In[1] & 15 ' Isolate the 4 lower bits (Out[2] now equals %00000001)
Out[2] = In[1] = In[1] << 2 ' Shift "up" two steps (Out[2] now equals %00000100)
Temp = (In[2] & 192) ' Isolate the 2 top bits in In[2] (Temp now equals %01000000)
Temp = In[2] >> 6 ' Shift it down 6 steps (Temp now equals %00000001)
Out[2] = Out[2] + Temp ' Add the two together (Out[2] now equals %00000101)
Out[2] = Out[2] & 63 ' Isolate the 6 lower bits
In fact, I wonder if the last step is actually needed....depends on what gets "shifted in" at the top but I guess that "should" be all zeros - perhaps room for improvement there....
/Henrik.
Bookmarks