Inverting a bit

I am trying to invert a bit, in this case Bit4

The following code:
Bit4 = Bit4 nand Bit4

Should I believe invert Bit4
as should:
Bit4 = Bit4 nor Bit4

However the Programming Editor returns errors on both, but not on:
Bit4 = Bit4 and Bit4
Bit4 = Bit4 or Bit4

What am I doing wrong????
 
guys
From the manual

Page 22 of the programming manual seams to differ;
"The mathematical functions supported by all parts are:..... NOR, NAND......
The 18M2 is highlighted as a part that has these functions.
I am still confused.

But the good news is that Bit4 = not bit4 works,
Hippy thanks: Again.
 

westaust55

Moderator
Yet another way to invert a bit:

bit1 = bit1 XOR 1

in terms of program space (based upon 08M and 40X1)
bit1 = bit1 XOR 1 ; 6 bytes time ~0.55 msec
bit1 = bit1 + 1 ; 6 bytes time ~0.60 msec
bit1 = not bit1 ; 8 bytes time ~0.70 msec

times to execute based on 40X1 and perfoming the command 20,000 times
 
Last edited:

hippy

Ex-Staff (retired)
Page 22 of the programming manual seams to differ;
"The mathematical functions supported by all parts are:..... NOR, NAND......
The 18M2 is highlighted as a part that has these functions.
I am still confused.
Apologies for the confusion. I'll get someone to check if the operator functions are supported and it's the compiler not handling things or whether the operators are X2 only.
 
WestAus55
in terms of program space (based upon 08M)
bit1 = bit1 XOR 1 ; 6 bytes 747
bit1 = not bit1 ; 8 bytes 747
bit1 = bit1 + 1 ; 10 bytes 745
I am using a 18M2 and the byte count I get is 747,747, & 745 for the 3 conditions above.

Hippy, looking forward to the reply.
Cheers
 

westaust55

Moderator
Looking at PICAXE manual 2 V5.2 from 2004 (yes ancient and far longer than I have been experimenting with microcontroller), these commands were available from pre X1 days:
The AND, OR, XOR, NAND, NOR and XNOR commands function bitwise on each bit in the variables.
EDIT:
bit1 = bit1 NAND bit1
bit1 = bit1 NOR bit1

works on all (tried 08M, 18X and 40X1) except for an M2 part as PE gives a syntax error for any M2 part.
 
Last edited:

hippy

Ex-Staff (retired)
bit1 = bit1 NAND bit1
bit1 = bit1 NOR bit1

works on all (tried 08M, 18X and 40X1) except for an M2 part as PE gives a syntax error for any M2 part.
Thanks for testing and letting us know. My guess would be there's been a hiccup in the M2 compilers no one had caught earlier which we will look into.
 
Top