General Bitmask Operator

Liste des GroupesRevenir à ol advocacy 
Sujet : General Bitmask Operator
De : ldo (at) *nospam* nz.invalid (Lawrence D'Oliveiro)
Groupes : comp.os.linux.advocacy
Date : 25. Mar 2024, 01:21:58
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <utqcim$kqor$3@dont-email.me>
User-Agent : Pan/0.155 (Kherson; fc5a80b8)
Here’s a generalized function that will implement any function that
takes two Boolean operands and returns a Boolean result. There are 16
possible such functions, and they are selected according to a mask
which defines the truth table:

    bool bitmask_op
      (
        bool a,
        bool b,
        unsigned int mask
      )
      {
        return
                not a and not b and (mask & 1) != 0
            or
                not a and b and (mask & 2) != 0
            or
                a and not b and (mask & 4) != 0
            or
                a and b and (mask & 8) != 0;
      } /*bitmask_op*/

Meanings of some mask values:

    mask    meaning
      0     always false
      1     nor
      3     not-a (ignore b)
      5     not-b (ignore a)
      6     exclusive-or
      7     nand
      8     and
     10     b (ignore a)
     11     a implies b
     12     a (ignore b)
     13     b implies a
     14     inclusive-or
     15     always true

Date Sujet#  Auteur
25 Mar 24 o General Bitmask Operator1Lawrence D'Oliveiro

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal