I am running into a problem using the NOT/! operator with byte variables. The program is as follows:
one=1zero=0wait1sHSerPrint"one and (not zero)"HSerPrintCRLFhserprintone&(!zero)HSerPrintCRLFHSerPrint"one or (not one)"HSerPrintCRLFHSerPrintone|(!one)HSerPrintCRLFHSerPrint"one xor (not one)"HSerPrintCRLFHSerPrintone#(!one)HSerPrintCRLFHSerPrint"not one"HSerPrintCRLFHSerPrint!oneHSerPrintCRLFHSerPrint"not zero"HSerPrintCRLFHSerPrint!zero
When one and zero variables are declared as bits the results of logical operations are ok even though !one and !zero show up as 254 and 255:
one and (not zero)
1
one or (not one)
1
one xor (not one)
0
not one
254 <---- ????
not zero
255 <---- ????
When one and zero variables are declared as byte (default) some of the results of the same logical operations are wrong:
one and (not zero)
1
one or (not one)
255 <---- Wrong
one xor (not one)
255 <---- Wrong
not one
254
not zero
255
Does it mean that the NOT operator cannot be used as a logical operator on byte variables (AND, OR, XOR are working ok on both bit & byte variables) ?
Jacques
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am running into a problem using the NOT/! operator with byte variables. The program is as follows:
When one and zero variables are declared as bits the results of logical operations are ok even though !one and !zero show up as 254 and 255:
When one and zero variables are declared as byte (default) some of the results of the same logical operations are wrong:
Does it mean that the NOT operator cannot be used as a logical operator on byte variables (AND, OR, XOR are working ok on both bit & byte variables) ?
Jacques
Can you confirm your microprocessor type?
Thank you.
16F690
I had the same question a year or so ago. I just cannot find Hugh's response but I was convinced by the response re the treatment of operators.
However, something is not right. I am getting the same results as you on PIC but different results on AVR.
@Hugh. Your view please.