NEGATE: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
(Initial version.)
 
m (Update See Also section)
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{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 7: Line 8:


{{PageDescription}}
{{PageDescription}}
* Unlike [[NOT]], which evaluates a value and returns the bitwise opposite, [[_NEGATE]] returns the logical opposite. Meaning that {{InlineCode}}NOT {{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}}_NEGATE {{Parameter|non_zero_value}} = 0{{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.
{{PageAvailability}}
<!-- QB64 = a version or none, QBPE = a version or all, Platforms = yes or no -->
<gallery widths="48px" heights="48px" mode="nolines">
File:Qb64.png|'''none'''
File:Qbpe.png|'''v3.13.0'''
File:Apix.png
File:Win.png|'''yes'''
File:Lnx.png|'''yes'''
File:Osx.png|'''yes'''
</gallery>
<!-- Additional availability notes go below the gallery -->




Line 19: Line 33:


{{Cl|IF}} {{Cl|NOT}} {{Text|isdigit|#55FF55}}({{Cl|ASC (function)|ASC}}({{Text|<nowiki>"1"</nowiki>|#FFB100}})) {{Cl|THEN}}
{{Cl|IF}} {{Cl|NOT}} {{Text|isdigit|#55FF55}}({{Cl|ASC (function)|ASC}}({{Text|<nowiki>"1"</nowiki>|#FFB100}})) {{Cl|THEN}}
     {{Cl|PRINT}} {{Text|<nowiki>"NOT: 1 is not a digit"</nowiki>|#FFB100}}
     {{Cl|PRINT}} {{Text|<nowiki>"NOT: 1 is not a digit."</nowiki>|#FFB100}}
{{Cl|ELSE}}
{{Cl|ELSE}}
     {{Cl|PRINT}} {{Text|<nowiki>"NOT: 1 is a digit."</nowiki>|#FFB100}}
     {{Cl|PRINT}} {{Text|<nowiki>"NOT: 1 is a digit."</nowiki>|#FFB100}}
Line 25: Line 39:


{{Cl|IF}} {{Cl|_NEGATE}} {{Text|isdigit|#55FF55}}({{Cl|ASC (function)|ASC}}({{Text|<nowiki>"1"</nowiki>|#FFB100}})) {{Cl|THEN}}
{{Cl|IF}} {{Cl|_NEGATE}} {{Text|isdigit|#55FF55}}({{Cl|ASC (function)|ASC}}({{Text|<nowiki>"1"</nowiki>|#FFB100}})) {{Cl|THEN}}
     {{Cl|PRINT}} {{Text|<nowiki>"_NEGATE: 1 is not a digit"</nowiki>|#FFB100}}
     {{Cl|PRINT}} {{Text|<nowiki>"_NEGATE: 1 is not a digit."</nowiki>|#FFB100}}
{{Cl|ELSE}}
{{Cl|ELSE}}
     {{Cl|PRINT}} {{Text|<nowiki>"_NEGATE: 1 is a digit."</nowiki>|#FFB100}}
     {{Cl|PRINT}} {{Text|<nowiki>"_NEGATE: 1 is a digit."</nowiki>|#FFB100}}
Line 32: 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}}
Line 41: Line 55:
* [[_BIT]], [[&B]], [[_BYTE]]
* [[_BIT]], [[&B]], [[_BYTE]]
* [[AND]], [[XOR]], [[OR]]
* [[AND]], [[XOR]], [[OR]]
* [[AND (boolean)]], [[XOR (boolean)]], [[OR (boolean)]]
* [[_ANDALSO]], [[_ORELSE]]
* [[Binary]], [[Boolean]]
* [[Binary]], [[Boolean]]
* [[Mathematical Operations]]
* [[Mathematical Operations]]

Latest revision as of 10:14, 1 May 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