05-09-2024, 05:55 PM
Now this entry should be a fairly short one for you guys, as it's just finishing up the last of our new LOGICAL operations -- _NEGATE.
As you guys should know by now, AND/OR are *binary* operators, while _ANDALSO/_ORELSE are *logical* operators. The first set does binary math comparison; the second set of commands simply check if values are 0 (FALSE) or not (TRUE).
Along the exact same line as these commands, we have both the old *binary* NOT and the new *logical* _NEGATE.
NOT takes a value and basically flips all the bits in it. For example, let's look at NOT 1:
00000001 <-- this is the 8-bit representation of 1 that is stored in a byte.
------------ <-- so lets apply NOT to that value here
11111110 <-- and there's the binary representation of what NOT 1 looks like.
NOT toggles bits for a number.
Now, as for _NEGATE, what does it do as a *logical* operator??
It returns the opposite of TRUE (-1) and FALSE (0) to us . A few brief examples would probably be best to clear up any misunderstanding here:
_NEGATE 1 = 0
_NEGATE 0 = -1
_NEGATE 14 = 0
_NEGATE 123.12 = 0
In BASIC, anything non-zero is considered TRUE, while *ONLY* zero is considered FALSE.
Logically, when you _NEGATE anything TRUE, you get back FALSE.... So if you _NEGATE any non-zero value, you will get back a return value of 0.
And if you _NEGATE a false value, you get back TRUE... In this case, the result is always going to be -1 -- what I guess we could consider to be *ABSOLUTE TRUE*.
NOT -1 = 0 ' NOT TRUE = FALSE
NOT 0 = -1 ' NOT FALSE = TRUE
When dealing with NOT, only 0 and -1 have this TRUE/FALSE inverse to them. Any other values will NOT TRUE = TRUE, as shown below:
NOT 1 = -2 '1 is TRUE, but -2 is also TRUE as it's non-zero
NOT -2 = 1' as above.
_NEGATE doesn't have this issue, as it only returns -1 and 0 as values. If you logically _NEGATE the truth of something, you end up with FALSE.
_NEGATE basically:
1) Returns 0 as the result for any non-zero value you negate.
2) Returns -1 as the result, if you send it a value of zero.
It's that simple of a command, at the end of the day.
As you guys should know by now, AND/OR are *binary* operators, while _ANDALSO/_ORELSE are *logical* operators. The first set does binary math comparison; the second set of commands simply check if values are 0 (FALSE) or not (TRUE).
Along the exact same line as these commands, we have both the old *binary* NOT and the new *logical* _NEGATE.
NOT takes a value and basically flips all the bits in it. For example, let's look at NOT 1:
00000001 <-- this is the 8-bit representation of 1 that is stored in a byte.
------------ <-- so lets apply NOT to that value here
11111110 <-- and there's the binary representation of what NOT 1 looks like.
NOT toggles bits for a number.
Now, as for _NEGATE, what does it do as a *logical* operator??
It returns the opposite of TRUE (-1) and FALSE (0) to us . A few brief examples would probably be best to clear up any misunderstanding here:
_NEGATE 1 = 0
_NEGATE 0 = -1
_NEGATE 14 = 0
_NEGATE 123.12 = 0
In BASIC, anything non-zero is considered TRUE, while *ONLY* zero is considered FALSE.
Logically, when you _NEGATE anything TRUE, you get back FALSE.... So if you _NEGATE any non-zero value, you will get back a return value of 0.
And if you _NEGATE a false value, you get back TRUE... In this case, the result is always going to be -1 -- what I guess we could consider to be *ABSOLUTE TRUE*.
NOT -1 = 0 ' NOT TRUE = FALSE
NOT 0 = -1 ' NOT FALSE = TRUE
When dealing with NOT, only 0 and -1 have this TRUE/FALSE inverse to them. Any other values will NOT TRUE = TRUE, as shown below:
NOT 1 = -2 '1 is TRUE, but -2 is also TRUE as it's non-zero
NOT -2 = 1' as above.
_NEGATE doesn't have this issue, as it only returns -1 and 0 as values. If you logically _NEGATE the truth of something, you end up with FALSE.
_NEGATE basically:
1) Returns 0 as the result for any non-zero value you negate.
2) Returns -1 as the result, if you send it a value of zero.
It's that simple of a command, at the end of the day.