NOT (Bitwise NOT) Negate?

retepsnikrep

Senior Member
I'm looking for a negate function, which I think is the same as NOT which doesn't seem to be supported in the mathematics commands?

So any ideas how to negate a hex value in b0?

I was thinking a loop looking at each bit and then flipping it but that seems long winded. I'm using an 18X at present.


I've just seen the NOT command is supported by the 28X2, hmm!
 
Last edited:

QuIcK

Senior Member
are you looking to invert a byte (bitwise not). eg:
b0 = %11101011
b0 = NOT b0
'b0 = %00010100

because the NOT command is supported by all models (as far as I know).

if you are looking to negate a number (eg, make 23 into -23) there are 2 ways, depending on which negative representation you want to use.
1's compliment, just change bit7:
b0 = %00101011 '(43)
b0 = b0 + $80 'adding 128, ie %10000000
'b0 = %10101011 (-43)

or 2's compliment:
b0 = %00101011 '(43)
b0 = NOT b0 '%11010100
b0 = b0 + 1 'add 1 to 2's compliment, there is a reason.
'b0 = 11010101 (-43)

im sure theres an easier way. like:
2's compliment:
b0 = %00101011 '(43)
b0 = 0 - b0 'should produce -43


EDIT:
just thought, do you want to reverse a byte?
so that 11010010 -> 01001011 ?
 

retepsnikrep

Senior Member
or 2's compliment:
b0 = %00101011 '(43)
b0 = NOT b0 '%11010100
b0 = b0 + 1 'add 1 to 2's compliment, there is a reason.
'b0 = 11010101 (-43)
This works for me thanks.

However it uses the NOT command which if you look at the manual the implication is that (NOT) is not available in the 18X, as it is not listed amongst the normal maths functions, but is next to a picture of the 28X2 and amongst some more complicated functions.

(Tech) does the manual need ammending?

It works in simulator for 18X though so looks promising. Thanks a lot.
 

BCJKiwi

Senior Member
AT the top of page 23 Manual section 2 ver 6.9 06/2009, the manual states:-

"Variables - Unary Mathematics
All parts support the NOT unary command e.g.
let b1 = NOT pins"

If that comment (and the Further Information below regarding NOT) were on the previous page, then the confusion would be removed as the page would then only contain the specific X1 and X2 additional functions which complete the page.

Hmm..... crossed with Technical's reply but still feel the suggested layout change would remove any confusion.
 

Technical

Technical Support
Staff member
Possibly, but NOT is technically a 'unary' command, hence the reason it is in the unary section.
 

BCJKiwi

Senior Member
Don't really want to get into an extended debate on this but for the uninitiated;

new page,
Left column shows only X1/X2
Hmm nothing here applies to my (non X1/X2)
Damn,
Move on.

Just too easy to be confused.
 
Top