inverting all bits in a byte
How do I invert all the bits in a byte?
Eg %011010110 would become %100101001
I assumed, then read it was by using the tilde (~) function but I'm having trouble using it in code.
eg if I had byteA=%011010110
and I did this: byteA=~byteA, shouldn't ~byteA display %100101001?
Strangely I can display the value of byteA in the display (LabX1) but ~byteA comes up empty.
Re: inverting all bits in a byte
how many bits in a byte ? not 9
Quote:
Eg %011010110 would become %100101001
Quote:
Strangely I can display the value of byteA in the display (LabX1) but ~byteA comes up empty.
what display? , how displayed ?
if its a common garden variety lcd , chrs in this range 127 < chr >160 are not in the built in font
so using var A = $66
A will print on lcd
~A ($99) will not print on lcd
Re: inverting all bits in a byte
There is a simple ASM command, COMF. This is what it would look like:
@ BANKSEL _byteA
@ COMF _byteA, F
The first line moves the BSR (Bank Select Register) to the BANK containing your variable. The variable is preceded by an underscore for ASM; _byteA.
The second line executes the command, Compliment F (F is your variable). The appending ", F" puts the result back in your variable, byteA.
Hope this helps
Re: inverting all bits in a byte
Use the ^ operator for Bitwise Exclusive OR
ByteA = ByteA ^ %11111111 Inverts the bits of ByteA
Re: inverting all bits in a byte
Re: inverting all bits in a byte
I have the new "enhanced" byte, with 9 bits.
Re: inverting all bits in a byte
Using comf would be about twice as fast there since you don’t have to do anything at all with the literal 0xFF.
Re: inverting all bits in a byte
Why not just use grandpa's way:
byte = 255- byte
Inverts the bits.