PDA

View Full Version : reading first four bits of a byte



kamet
- 2nd January 2007, 02:22
if i have a hex byte, say "FF", is there something to read the first 4 bits and last 4 bits individually? or put it into another variable? Something simliar to reading a WORD variable using ".highbyte" and ".lowbyte"

I am currently doing this this way:

nibholderLow.0 = myvar.0
nibholderLow.1 = myvar.1
nibholderLow.2 = myvar.2
nibholderLow.3 = myvar.3

nibholderHigh.0 = myvar.4
nibholderHigh.1 = myvar.5
nibholderHigh.2 = myvar.6
nibholderHigh.3 = myvar.7

Basically, nibholderLow is a variable which holds first 4 bits of the byte FF, (ie. 15) and the other one, nibholderHigh holds the other F.

the variable myvar is constantly changing, I can't declare this conversion at the very top.

Darrel Taylor
- 2nd January 2007, 03:13
nibholderHigh = myvar >> 4
nibholderLow = myvar & $F
<br>

kamet
- 2nd January 2007, 08:50
ahh thanks! so simple yet it never occured to me.

much thanks again!