inverting all bits in a byte

# Thread: inverting all bits in a byte

1. ## 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.

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.

2. ## Re: inverting all bits in a byte

how many bits in a byte ? not 9

Eg %011010110 would become %100101001
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

3. ## 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

4. ## Re: inverting all bits in a byte

Use the ^ operator for Bitwise Exclusive OR

ByteA = ByteA ^ %11111111 Inverts the bits of ByteA

thanks Dick

6. ## Re: inverting all bits in a byte

I have the new "enhanced" byte, with 9 bits.

7. ## 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.

8. ## Re: inverting all bits in a byte

Why not just use grandpa's way:

byte = 255- byte

Inverts the bits.

You do not have permission to view the list of names.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts