# Getting info out of a byte in bits.

I’m in need of splitting a Byte into 6 bits and 2 bits.

For this i have the following specification:
The high 6 bits are frequency parameter; the low 2 bits are antenna ID.

High 6 bits = Frequency
Low 2 bits = AntennaID

Is there a way to get this in xojo from getting a Byte/Uint8 and extracting the 2 parameter values to make something usefull?

[code] dim source As UInt8 = &b01001010

Dim frequency As Uint8 = Bitwise.BitAnd(&b11111100, source)
Dim ID As Uint8 = Bitwise.BitAnd(&b00000011, source)

msgbox str(frequency)+ " " + str(ID)[/code]

You get: 72 2

One modification to Ramon’s on-point suggestion: You don’t need “Bitwise” here. A simple “and” will do, and is faster (if that matters).

``````  Dim frequency As Uint8 = &b11111100 and source
Dim ID As Uint8 = &b00000011 and source``````

In fact, the only place you “need” Bitwise these days are when you need ShiftLeft and ShiftRight, although multiplying/dividing by 2^places would do the same thing if you don’t need the second parameter of ShiftLeft/ShiftRight.

Oh, for the frequency, you probably have to shift right two places:

``dim frequency as byte = Bitwise.ShiftRight( &b11111100 and source, 2 )``

[quote=239659:@Kem Tekinay]Oh, for the frequency, you probably have to shift right two places:

``` dim frequency as byte = Bitwise.ShiftRight( &b11111100 and source, 2 ) ```[/quote]
Yes, you are right! I made a mistake.

Thanks all will test this tomorrow!