Programming


Logic


One and Two Input Gates

AND Gate NAND Gate

A AND B

A NAND B

Output is TRUE only if both inputs are TRUE.

Output is FALSE only if both inputs are TRUE.

A    Boutput
F    FF
F    TF
T    FF
T    TT

A    Boutput
F    FT
F    TT
T    FT
T    TF
OR Gate NOR Gate

A OR B

A NOR B

Output is TRUE if either input (or both) is TRUE.

Output is FALSE if either input (or both) is TRUE.

A    Boutput
F    FF
F    TT
T    FT
T    TT

A    Boutput
F    FT
F    TF
T    FF
T    TF
EXCLUSIVE OR (XOR) Gate EXCLUSIVE NOR (XNOR) Gate
(or Equality Gate)

A XOR B

A XNOR B

Output is TRUE if either (but not both) input is TRUE.

Output is FALSE if either (but not both) input is TRUE.

A    Boutput
F    FF
F    TT
T    FT
T    TF

A    Boutput
F    FT
F    TF
T    FF
T    TT
Inverter
(or NOT Function or Compliment Function)

NOT A

Aoutput
FT
TF


Three Input Gates

AND Gate NAND Gate

A AND B AND C

A NAND B NAND C

Output is TRUE only if all inputs are TRUE.

Output is FALSE only if all inputs are TRUE.

A    B    Coutput
F    F    FF
F    F    TF
F    T    FF
F    T    TF
T    F    FF
T    F    TF
T    T    FF
T    T    TT

A    B    Coutput
F    F    FT
F    F    TT
F    T    FT
F    T    TT
T    F    FT
T    F    TT
T    T    FT
T    T    TF
OR Gate NOR Gate

A OR B OR C

A NOR B NOR C

Output is TRUE if any input (or all) is TRUE.

Output is FALSE if any input (or all) is TRUE.

A    B    Coutput
F    F    FF
F    F    TT
F    T    FT
F    T    TT
T    F    FT
T    F    TT
T    T    FT
T    T    TT

A    B    Coutput
F    F    FT
F    F    TF
F    T    FF
F    T    TF
T    F    FF
T    F    TF
T    T    FF
T    T    TF


Boolean Algebra Theorems

AND theorems 0 · 0 = 0 A · 1 = A
1 · 1 = 1 A · A = A
1 · 0 = 0 A · A = 0
A · 0 = 0
OR theorems 1 + 1 = 1 A + 0 = A
0 + 0 = 0 A + A = A
1 + 0 = 1 A + /A = 1
A + 1 = 1
NOT /0 = 1 /1 = 0
//A = A
Commutation A + B = B + A A · B = B · A
Absorption A + A · B = A A · (A + B) = A
Association A + (B + C) = (A + B) + C A · (B · C) = (A · B) · C
Distribution A + B · C = (A + B) · (A + C) A · (B + C) = A · B + A · C
DeMorgan's theorems /A + /B = /A · /B /A · /B = /A + /B


Useful Logical Programming Tools

IF N AND 1 THEN Tests if a number is odd (has its 1 bit set)
N + N AND -2 Always gives the even number of a pair, so if you are calculating an offset into a buffer, this always places you at an even-numbered position.
N = N AND X Keeps a variable within a range X.
So N AND 16383 insures that an integer never exceeds 16383.
N = N AND 127 Strips the high bit from characters such as for sending to a serial port.
N = N OR 128 Sets the high bit (in some cases this signals an attribute such as underlining).
N = N AND 95 Resets bit 6 to 0 so ASCII characters are upper case.
Replaces IF (ASCII) CODE N) > 96 THEN N = N - 32.
N = N OR 32 Makes all letters lower case by setting bit 6.
N = N OR 48 Converts the digits 0 to 9 into their printable ASCII codes (sets bits 5 and 6).
IF X OR Y If either X or Y has a nonzero value ...
X = X XOR 1 Sets a flag variable from 1 or -1 to 0 and back.
Replaces IF X THEN X = 0 ELSE X = 1.
PAGE = PAGE XOR 3 XOR can be used jump back and forth between two values, here between video pages 1 and 2.
The value that toggles between has 1's where changes occur and 0 where they don't, for example to switch between
300000011
and 4500101101
use 4600101110
T = T + 1 AND 3 This can be used to maintain a cycle.
Replaces T = T + 1: IF T = 4 THEN T = 0.
T = 1 - T Toggles between 1 and 0.


Notes

False = 0
True = 1
 
Positive Logic (or Positive True Logic or High True Logic)
False or 0 = LOW
True or 1 = HIGH
 
Negative Logic (or Negative True Logic or Low True Logic)
False or 0 = HIGH
True or 1 = LOW
 
Bit_Logic.vi:  A LabVIEW program that demonstrates bit-wise logic operations.

[  Index  |  Technical Notes Page  ]

This page is for INFORMATIONAL PURPOSES ONLY.

Page author: Dawn Rorvik (rorvikd@evergreen.edu)
Last modified: 04/20/2000