GP32 Bitwise Operators


pea

developer
Joined
Oct 3, 2004
Messages
1,089
Age
45
Location
New Zealand
Website
www.projectitis.com
Hey all,

I thought that &/ was NAND? gcc doesn't seem to recognise it.
I can use:
& AND
| OR

But I need either XOR or NAND (to invert a binary number) any ideas?

example: For a byte 'n' (0-255)
n NAND n will invert (e.g. 10011101 => 01100010 )
n XOR 255 will invert (e.g. 00011100 => 11100011 )
 
~ will invert, or just n^-1 (xor -1, where -1 is 0xff for a byte)
 
If I recall correct:
&: binary and
&&: logical and
|: binary or
||: logical or
^: binary xor
^^: logical xor
~: binary not
!: logical not

From that nand should be: ~(a & B) as binary / !(a && B) as logical
The difference between logical and binary is that the result of logical is always 0 or 1 and the operators are always looked at as boolean (either 0 or != 0).
So, (1 & 2) == 0, but (1 && 2) == 1

Greetings from Germany,
SvOlli
 
Back
Top