2012年12月5日 星期三

Programming --> Logic

Programming


Logic

One and Two Input Gates

AND GateNAND 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
0    00
0    10
1    00
1    11
(The AND gate is useful for masking or clearing specified bit positions.)

A    Boutput
F    FT
F    TT
T    FT
T    TF
      
A    Boutput
0    01
0    11
1    01
1    10
OR GateNOR 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
0    00
0    11
1    01
1    11
(The OR gate is useful for setting specified bits.)

A    Boutput
F    FT
F    TF
T    FF
T    TF
      
A    Boutput
0    01
0    10
1    00
1    10
XOR (EXCLUSIVE OR) GateXNOR (EXCLUSIVE NOR) Gate
(or Equality Gate)

A XOR B

A XNOR B

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

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

A    Boutput
F    FF
F    TT
T    FT
T    TF
      
A    Boutput
0    00
0    11
1    01
1    10
(The XOR gate is useful for complementing specified bits.)

A    Boutput
F    FT
F    TF
T    FF
T    TT
      
A    Boutput
0    01
0    10
1    00
1    11
NOT Function
(or Inverter or Complement Function)
 

NOT A
 

Aoutput
FT
TF
      
Aoutput
01
10
(The NOT function is useful for complementing every bit.)
 


Three Input Gates

AND GateNAND 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
0    0    00
0    0    10
0    1    00
0    1    10
1    0    00
1    0    10
1    1    00
1    1    11

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
      
A    B    Coutput
0    0    01
0    0    11
0    1    01
0    1    11
1    0    01
1    0    11
1    1    01
1    1    10
OR GateNOR 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
0    0    00
0    0    11
0    1    01
0    1    11
1    0    01
1    0    11
1    1    01
1    1    11

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
      
A    B    Coutput
0    0    01
0    0    10
0    1    00
0    1    10
1    0    00
1    0    10
1    1    00
1    1    10
XOR (EXCLUSIVE OR) GateXNOR (EXCLUSIVE NOR) Gate

A OR B OR C

A NOR B NOR C

A    B    Coutput
F    F    FF
F    F    TT
F    T    FT
F    T    TF
T    F    FT
T    F    TF
T    T    FF
T    T    TT
      
A    B    Coutput
0    0    00
0    0    11
0    1    01
0    1    10
1    0    01
1    0    10
1    1    00
1    1    11

A    B    Coutput
F    F    FT
F    F    TF
F    T    FF
F    T    TT
T    F    FF
T    F    TT
T    T    FT
T    T    TF
      
A    B    Coutput
0    0    01
0    0    10
0    1    00
0    1    11
1    0    00
1    0    11
1    1    01
1    1    10


Boolean Algebra Theorems

AND theorems0 · 0 = 0A · 1 = A
1 · 1 = 1A · A = A
1 · 0 = 0A · /A = 0
A · 0 = 0 
OR theorems1 + 1 = 1A + 0 = A
0 + 0 = 0A + A = A
1 + 0 = 1A + /A = 1
A + 1 = 1 
NOT/0 = 1/1 = 0
//A = A 
CommutationA + B = B + AA · B = B · A
AbsorptionA + A · B = AA · (A + B) = A
AssociationA + (B + C) = (A + B) + CA · (B · C) = (A · B) · C
DistributionA + 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 THENTests if a number is odd (has its bit 1 set)
N + N AND -2Always 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 XKeeps a variable within a range X.
So N AND 16383 insures that an integer never exceeds 16383.
N = N AND 127Clears the high bit (bit 8) in characters such as for sending to a serial port.
N = N OR 128Sets the high bit (bit 8) in characters. In some cases this signals an attribute such as underlining.
N = N AND 95Changes an lower case ASCII letter character to upper case by clearing bit 6.
Replaces IF (ASCII CODE N) > 96 THEN N = N - 32.
N = N OR 32Changes an upper case ASCII letter character to lower case by setting bit 6.
N = N AND 15Converts an ASCII number character into its decimal number value by clearing bits 5 and 6.
N = N OR 48Converts the digits 0 to 9 into their printable ASCII codes by setting bits 5 and 6.
IF X OR YIf either X or Y has a nonzero value ...
X = X XOR 1Sets a flag variable from 1 or -1 to 0 and back.
Replaces IF X THEN X = 0 ELSE X = 1.
PAGE = PAGE XOR 3XOR 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
 3 00000011
and 45 00101101
use 46 00101110
X = X + 1 AND 3This can be used to maintain a cycle.
Replaces X = X + 1: IF X = 4 THEN X = 0.
X = 1 - XToggles a variable between 1 and 0.


Notes

FALSE = F = 0
TRUE = T = 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.

Other Resources


[  Index  |  Technical Notes  ]

DISCLAIMER
Page author: Dawn Rorvik (rorvikd@evergreen.edu)
Last modified: 11/17/2006

沒有留言:

張貼留言

2024產專班 作業2 (純模擬)

2024產專班 作業2  (純模擬) 1) LED ON,OFF,TIMER,FLASH 模擬 (switch 控制) 2)RFID卡號模擬 (buttom  模擬RFID UID(不從ESP32) Node-Red 程式 [{"id":"d8886...