Template:LogicalTruthPlugin: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{FixedStart}}
{{FixedStart}}
  The results of the bitwise logical operations, where '''A''' and '''B''' are operands,
              Table 4: The logical operations and its results.
            and '''1''' or '''0''' indicate whether a bit is set or not set:
 
    ┌───────────┬────────────────────────────────────────────────────────┐
      In this table, '''A''' and '''B''' are the [[Expression|Expressions]] to invert or combine.
    │ '''Operands'''                    '''Logical operations'''                  
              Both may be results of former [[Boolean]] evaluations.
    ├─────┬─────┼───────┬─────────┬────────┬─────────┬─────────┬─────────┤
  ┌────────────────────────────────────────────────────────────────────────┐
    '''A''' '''B''' │ [[NOT]] '''B''' │ '''A''' [[AND]] '''B''' │ '''A''' [[OR]] '''B''' │ '''A''' [[XOR]] '''B''' │ '''A''' [[EQV]] '''B''' │ '''A''' [[IMP]] '''B''' │
                            '''Logical Operations'''                          
    ├─────┼─────┼───────┼─────────┼────────┼─────────┼─────────┼─────────┤
  ├───────┬───────┬───────┬─────────┬────────┬─────────┬─────────┬─────────┤
    '''1'''  │ '''1'''  │  0   │   1    │  1      0    │    1    │    1   
    '''A'''     '''B'''   │ [[NOT]] '''B''' │ '''A''' [[AND]] '''B''' │ '''A''' [[OR]] '''B''' │ '''A''' [[XOR]] '''B''' │ '''A''' [[EQV]] '''B''' │ '''A''' [[IMP]] '''B''' │
    ├─────┼─────┼───────┼─────────┼────────┼─────────┼─────────┼─────────┤
  ├───────┼───────┼───────┼─────────┼────────┼─────────┼─────────┼─────────┤
    '''1'''  │ '''0'''  │   1   │   0    │   1      1      0    │    0   
  │ '''true'''  │ '''true'''  │ false │  true   │ true   │ false  true   │ true 
    ├─────┼─────┼───────┼─────────┼────────┼─────────┼─────────┼─────────┤
  ├───────┼───────┼───────┼─────────┼────────┼─────────┼─────────┼─────────┤
    '''0''' '''1'''  │   0    0    │  1      1      0      1   
  │ '''true'''  │ '''false''' │ true false  │ true   │ true   │ false  false 
    ├─────┼─────┼───────┼─────────┼────────┼─────────┼─────────┼─────────┤
  ├───────┼───────┼───────┼─────────┼────────┼─────────┼─────────┼─────────┤
    '''0''' '''0'''  │   1    0    │  0      0    │    1    │    1    │
  │ '''false''' │ '''true'''  │ false false  true   │ true  false  true 
    └─────┴─────┴───────┴─────────┴────────┴─────────┴─────────┴─────────┘
  ├───────┼───────┼───────┼─────────┼────────┼─────────┼─────────┼─────────┤
    [[Relational Operations]] return '''negative one''' (-1, all bits set) and '''zero'''
  │ '''false''' │ '''false''' │ true  │  false false  false  true   │ true 
  (0, no bits set) for '''true''' and '''false''', respectively. This allows relational
  └───────┴───────┴───────┴─────────┴────────┴─────────┴─────────┴─────────┘
  tests to be inverted and combined using the bitwise logical operations.
   '''Note:''' In most BASIC languages incl. QB64 these are '''bitwise''' operations,
        hence the logic is performed for each corresponding bit in both
        operators, where '''true''' or '''false''' indicates whether a bit is '''set''' or
        '''not set'''. The outcome of each bit is then placed into the respective
        position to build the bit pattern of the final result value.
 
  As all [[Relational Operations]] return negative one (-1, '''all bits set''') for
    '''true''' and zero (0, '''no bits set''') for '''false''', this allows us to use these
    bitwise logical operations to invert or combine any relational checks,
    as the outcome is the same for each bit and so always results into a
            '''true''' (-1) or '''false''' (0) again for further evaluations.
{{FixedEnd}}
{{FixedEnd}}

Latest revision as of 00:28, 15 December 2022

               Table 4: The logical operations and its results.

       In this table, A and B are the Expressions to invert or combine.
              Both may be results of former Boolean evaluations.
  ┌────────────────────────────────────────────────────────────────────────┐
  │                           Logical Operations                           │
  ├───────┬───────┬───────┬─────────┬────────┬─────────┬─────────┬─────────┤
  │   ABNOT BA AND BA OR BA XOR BA EQV BA IMP B │
  ├───────┼───────┼───────┼─────────┼────────┼─────────┼─────────┼─────────┤
  │ truetrue  │ false │  true   │ true   │  false  │  true   │  true   │
  ├───────┼───────┼───────┼─────────┼────────┼─────────┼─────────┼─────────┤
  │ truefalse │ true  │  false  │ true   │  true   │  false  │  false  │
  ├───────┼───────┼───────┼─────────┼────────┼─────────┼─────────┼─────────┤
  │ falsetrue  │ false │  false  │ true   │  true   │  false  │  true   │
  ├───────┼───────┼───────┼─────────┼────────┼─────────┼─────────┼─────────┤
  │ falsefalse │ true  │  false  │ false  │  false  │  true   │  true   │
  └───────┴───────┴───────┴─────────┴────────┴─────────┴─────────┴─────────┘
   Note: In most BASIC languages incl. QB64 these are bitwise operations,
         hence the logic is performed for each corresponding bit in both
         operators, where true or false indicates whether a bit is set or
         not set. The outcome of each bit is then placed into the respective
         position to build the bit pattern of the final result value.

   As all Relational Operations return negative one (-1, all bits set) for
    true and zero (0, no bits set) for false, this allows us to use these
    bitwise logical operations to invert or combine any relational checks,
    as the outcome is the same for each bit and so always results into a
            true (-1) or false (0) again for further evaluations.