Wireshark-dev: Re: [Wireshark-dev] dissecting bits versus bytes
From: Ankith Agarwal <[email protected]>
Date: Mon, 9 May 2011 09:20:21 +0530 (IST)
  You can directly take the mask and convert them into hex.
Example: If you want to extract bits 5-8 then the mask is 0xf0(11110000),
for bit 4 the value is 0x08(00001000), for bit 3&2 the value is
0x06(00000110), for the last bit the value is 0x01(00000001).
By this way there is no need of performing shift operations, also you
don't have to maintain indexes.

On Sat, May 7, 2011, Brian Oleksa <[email protected]> said:

> Anders
> Yes.... I was able to figure this out.
> <4 bits> <1 bit> <2 bits> <1 bit>
>          0xf         0x1     0x3        0x1
> but then you have to shift the results:
>          0xf0       0x8     0x6        0x1
> to make room for the other fields.
> BUT...I ran into a little snag.
> I figured out that I must read 4 bits from the "end" of the byte (which 
> will give me 0010). This means I need to take bits 5-8 to construct the 
> version field...and use
> bit 4 for x...and then use bit 3 and 2 for y and then bit 1 for z.
> So this means I not only need to keep an index to the actual byte I am 
> on, but the individual bit index as well.
> How would I do this within the wireshark code..?
> Thanks,
> Brian

This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.