NEGATE: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
m (Update See Also section)
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{DISPLAYTITLE:_NEGATE}}
{{DISPLAYTITLE:_NEGATE}}
[[_NEGATE]] is a [[Boolean|boolean]] logical operator that will change a false statement to a true one and vice-versa.
'''_NEGATE''' is a [[Boolean|boolean]] logical operator that will change a false statement to a true one and vice-versa.




Line 8: Line 8:


{{PageDescription}}
{{PageDescription}}
* Unlike [[NOT]], which evaluates a value and returns the bitwise opposite, [[_NEGATE]] returns the logical opposite. Meaning that {{InlineCode}}_NEGATE {{Parameter|non_zero_value}} = 0{{InlineCodeEnd}}.
* Unlike [[NOT]], which evaluates a value and returns the bitwise opposite, '''_NEGATE''' returns the logical opposite. Meaning that {{InlineCode}}{{Cl|_NEGATE}} non_zero_value = {{Text|0|#F580B1}}{{InlineCodeEnd}}.
* Often called a negative logic operator, it returns the opposite of a value as true or false.
* Often called a negative logic operator, it returns the opposite of a value as true or false.


Line 22: Line 22:
File:Osx.png|'''yes'''
File:Osx.png|'''yes'''
</gallery>
</gallery>
<!-- Additional availability notes go below the gallery -->
<!-- Additional availability notes go below here -->




{{PageExamples}}
{{PageExamples}}
''Example:'' NOT versus _NEGATE
;Example: NOT versus _NEGATE
{{CodeStart}}
{{CodeStart}}
{{Cl|DECLARE LIBRARY}}
{{Cl|DECLARE LIBRARY}}
     {{Cl|FUNCTION}} {{Text|isdigit&|#55FF55}} ({{Cl|BYVAL}} n {{Cl|AS}} {{Cl|LONG}})
     {{Cl|FUNCTION}} {{Text|isdigit&amp;|#55FF55}} ({{Cl|BYVAL}} n {{Cl|AS}} {{Cl|LONG}})
{{Cl|END DECLARE}}
{{Cl|END DECLARE}}


Line 46: Line 46:
{{Cl|END}}
{{Cl|END}}
{{CodeEnd}}
{{CodeEnd}}
{{OutputStart}}NOT: 1 is not a digit.
{{OutputStart}}
NOT: 1 is not a digit.
_NEGATE: 1 is a digit.
_NEGATE: 1 is a digit.
{{OutputEnd}}
{{OutputEnd}}
:''Explanation:'' NOT is a bitwise operator that inverts all the bits in an integer, whereas _NEGATE is a logical operator that flips the truth value of a boolean expression.
{{PreStart}}
'''Explanation'''
[[NOT]] is a bitwise operator that inverts all the bits in an integer,
whereas '''_NEGATE''' is a logical operator that flips the truth value of
a boolean expression.
{{PreEnd}}




{{PageSeeAlso}}
{{PageSeeAlso}}
* [https://qb64phoenix.com/forum/showthread.php?tid=2671 Featured in our "Keyword of the Day" series]
* [[_BIT]], [[&B]], [[_BYTE]]
* [[_BIT]], [[&B]], [[_BYTE]]
* [[AND]], [[XOR]], [[OR]]
* [[AND]], [[XOR]], [[OR]]

Latest revision as of 20:54, 8 December 2024

_NEGATE is a boolean logical operator that will change a false statement to a true one and vice-versa.


Syntax

result = _NEGATE value


Description

  • Unlike NOT, which evaluates a value and returns the bitwise opposite, _NEGATE returns the logical opposite. Meaning that _NEGATE non_zero_value = 0.
  • Often called a negative logic operator, it returns the opposite of a value as true or false.


Availability


Examples

Example
NOT versus _NEGATE
DECLARE LIBRARY
    FUNCTION isdigit& (BYVAL n AS LONG)
END DECLARE

IF NOT isdigit(ASC("1")) THEN
    PRINT "NOT: 1 is not a digit."
ELSE
    PRINT "NOT: 1 is a digit."
END IF

IF _NEGATE isdigit(ASC("1")) THEN
    PRINT "_NEGATE: 1 is not a digit."
ELSE
    PRINT "_NEGATE: 1 is a digit."
END IF

END
NOT: 1 is not a digit.
_NEGATE: 1 is a digit.
Explanation
 NOT is a bitwise operator that inverts all the bits in an integer,
 whereas _NEGATE is a logical operator that flips the truth value of
 a boolean expression.


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link