Problem with bits in byte array....


Closed Thread
Results 1 to 16 of 16

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default Re: Problem with bits in byte array....

    Henrik,
    Yes, I mistakingly was thinking that some 'W=' takes the two consecutive bytes. Also array[0] and [1] confuses me at times with for-next etc. so I just consider array start at [1].
    What you coded is good. The top and bottom (out[0] and out[3]) are simple but the ones where the 6 bit straddle 2 bytes take a little more. I tried to follow your calc on out[2] but my brain started smoking. Just wondering if '+' changes the value as opposed to the '>>' and '<<' and &. But, if it works, never argue with success.
    Anyway, thats all a relatively small simple code.
    Don

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Problem with bits in byte array....

    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.

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts