Quote: "It's mostly used for bit operations"
Here's a quick explanation:
Decimal 12 = Binary 00001100
Decimal 15 = Binary 00001111
So, 12 NOT 15 equates to comparing the 8 bits of the two numbers.
If they are
NOT the same it results in a 1 and if they
are the same you get a 0.
So, working from left to right in both, the first 4 bits are 0 (the same) which gives you 0000.
The next two bits are 1's in both so being the same again results in two more 0's.
The last two bits of each are 00 and 11 and as they are
NOT the same results in 1 for each bit. So the whole operation would be:
00001100
00001111
-----------
00000011
In decimal, 00000011 = 3, so
12 NOT 15 actually equals 3.
In DBC, as Latch says, ! doesn't work correctly - it actually works like <> (not equals) and 12 ! 15 incorrectly returns 1 to say that it doesn't equal, so to be honest there's no point using it in that context.
NOT is not the same as NOT EQUALS.
As well as NOT, you also have...
AND (1 bit on AND the other):
00001100
00001111
-----------
00001100 << 12 AND 15 = 12
OR (1 bit on OR the other or both):
00001100
00001111
-----------
00001111 << 12 OR 15 = 15
XOR - Exclusive OR (1 bit on OR the other but not both):
00001100
00001111
-----------
00000011 << 12 XOR 15 = 3
The operators =, <>, <, >, <= and >= are not the same thing. Neither are the AND and OR used in If..Then statements.
And, if you are wondering what possible use you would have for OR, XOR, AND and NOT, you've just discovered one of the reasons why DB makes life so much easier for you compared to the earlier days when I started programming.
For example, you now have sprites and 'transparency flags' with image commands so you can see the background through black sections.
Years ago, to get an image onto the screen without being surrounded by a black box I had to:
* Create a mask from the image
* Paste the mask onto the screen leaving a 'hole' where the image data should be
* Paste the image on the screen only putting pixels where the hole is.
Comparing the bits of the pixels in the image and the mask to see which were on, which were off and which were both on or off had to be done with OR, XOR, AND and NOT.
TDK_Man