Confused on what I am getting with highbit() and lowbit()
John Kauffman
Posts: 653
I haven't been able to get what I expect when using myByte.highbit() and MyByte.lowbit(). (short demo program attached).
I've been searching fora but must not be using proper terms.
I'm trying to get the bits out of a byte representing an ASCII char for example: g is 01100111. But counting up or down, high or low first, I can't seem to get the right pattern when I loop through the bits. I thought it would be:
'?????
' sample: h = 01101000
' = msb...lsb
' = HighBit(0)...HighBit(3) LowBit(0)...LowBit(3)
' ?????
I would appreciate a pointer to where I can learn the syntax to get a given bit as I count it off in the BIN representation of a byte
thanksBitstreamDemoVer01.bs2
I've been searching fora but must not be using proper terms.
I'm trying to get the bits out of a byte representing an ASCII char for example: g is 01100111. But counting up or down, high or low first, I can't seem to get the right pattern when I loop through the bits. I thought it would be:
'?????
' sample: h = 01101000
' = msb...lsb
' = HighBit(0)...HighBit(3) LowBit(0)...LowBit(3)
' ?????
I would appreciate a pointer to where I can learn the syntax to get a given bit as I count it off in the BIN representation of a byte
thanksBitstreamDemoVer01.bs2
Comments
I think your loop that references .lowbit should be ok. That accesses bits 0, 1, 2, and 3 in that order. If you want to access the next 4 bits, use .lowbit(BitCounter+4).
There are all sorts of other ways to do this. I would probably use the least significant bit for the output datastream and shift the character right one bit for each loop to get all 8 bits in order. That's the way most hardware does it.
If you can afford to use a word to hold the character, this loop acts like most hardware: