%Digital Electronics %Diego Trapero
The binary numeral system, or base-2 numeral system, represents numeric values using two symbols: typically 0 and 1. More specifically, the usual base-2 system is a positional notation with a radix of 2. #
0 | 0000 | 0 |
1 | 0001 | 1 |
2 | 0010 | 2 |
3 | 0011 | 3 |
4 | 0100 | 4 |
5 | 0101 | 5 |
6 | 0110 | 6 |
7 | 0111 | 7 |
8 | 1000 | 8 |
9 | 1001 | 9 |
10 | 1010 | A |
11 | 1011 | B |
12 | 1100 | C |
13 | 1101 | D |
14 | 1110 | E |
15 | 1111 | F |
Powers of 2
0 | 1 |
1 | 2 |
2 | 4 |
3 | 8 |
4 | 16 |
5 | 32 |
6 | 64 |
7 | 128 |
8 | 264 |
9 | 512 |
10 | 1024 |
Numbers you can represent with
System | Range |
---|---|
Natural binary |
|
One's complement |
|
Two's complement |
|
Digit weighting
\vspace{50mm}
Sum of weights
\vspace{50mm}
Repeated division by 2
\vspace{50mm}
Addition rules
$0 + 0 = 0$ $0 + 1 = 1$ $1 + 0 = 1$ -
$1 + 1 = 10$ (1 and carry 1)
1 1 1 1 1 (carried digits)
0 1 1 0 1
+ 1 0 1 1 1
-------------
= 1 0 0 1 0 0 = 36
\vspace{50mm}
Substraction rules
$0 - 0 = 0$ $0 - 1 = 0$ $1 - 0 = 1$ $10 - 1 = 1$
* * * * (starred columns are borrowed from)
1 1 0 1 1 1 0
- 1 0 1 1 1
----------------
= 1 0 1 0 1 1 1
\vspace{50mm}
Multiplication rules
$0 \cdot 0 = 0$ $0 \cdot 1 = 0$ $1 \cdot 0 = 0$ $1 \cdot 1 = 1$
1 0 1 1 (A)
× 1 0 1 0 (B)
---------
0 0 0 0 ← Corresponds to the rightmost 'zero' in B
+ 1 0 1 1 ← Corresponds to the next 'one' in B
+ 0 0 0 0
+ 1 0 1 1
---------------
= 1 1 0 1 1 1 0
1 0 1 . 1 0 1 A (5.625 in decimal)
× 1 1 0 . 0 1 B (6.25 in decimal)
-------------------
1 . 0 1 1 0 1 ← Corresponds to a 'one' in B
+ 0 0 . 0 0 0 0 ← Corresponds to a 'zero' in B
+ 0 0 0 . 0 0 0
+ 1 0 1 1 . 0 1
+ 1 0 1 1 0 . 1
---------------------------
= 1 0 0 0 1 1 . 0 0 1 0 1 (35.15625 in decimal)
\vspace{50mm}
\vspace{30mm}
In mathematics and computing, the method of complements is a technique used to subtract one number from another using only addition of positive numbers. This method was commonly used in mechanical calculators and is still used in modern computers. To subtract a number y (the subtrahend) from another number x (the minuend), the radix complement of y is added to x and the initial '1' of the result is discarded. Discarding the initial '1' is especially convenient on calculators or computers that use a fixed number of digits: there is nowhere for it to go so it is simply lost during the calculation. #
1's Complement
The One's complement of a binary number is defined as the value obtained by inverting all the bits in the binary representation of the number (swapping 0s for 1s and vice-versa). #
The ones' complement of the number then behaves like the negative of the original number in some arithmetic operations, although it presents some problems that are solved by the two's complement, like the offset by -1.
Examples
2's Complement
Obtain the 2's complement
-
From the 1's complement
$$2C[x] = 1c[x] + 1$$ -
Working from LSB to MSB
\vspace{50mm}
Sign-magnitude form \vspace{50mm}
1's complement form \vspace{50mm}
2's complement form \vspace{50mm}
- Basic gates perform the three basic boolean operations: conjunction (AND), disjunction (OR) and negation (NOT). Only one the two other gates is neccesary in conjuntion with the NOT gate to implement everty boolean function. The other operation can be expressed in therms of the other two.
- Derived gates perform derived boolean operations, operations that can be composed from basic operations. The most common are NAND, NOR, XOR, and XNOR gates.
$$ \begin{circuitikz} \draw (0,0) nodenot port {} (notGate.in) node[left] {$A$} (notGate.out) node[right] {$\text{NOT } A$} ; \end{circuitikz} $$
Rule: The NOT gate output is the complementary of the input
A | NOT A |
---|---|
0 | 1 |
1 | 0 |
$$ \begin{circuitikz} \draw (0,0) nodeand port {} (andGate.in 1) node[left] {$A$} (andGate.in 2) node[left] {$B$} (andGate.out) node[right] {$A \text{ AND } B$} ; \end{circuitikz} $$
Rule: The AND gate output is 1 only when all the inputs are 1.
A | B | A AND B |
---|---|---|
0 | 0 | 0 |
0 | 1 | 0 |
1 | 0 | 0 |
1 | 1 | 1 |
$$ \begin{circuitikz} \draw (0,0) nodeor port {} (orGate.in 1) node[left] {$A$} (orGate.in 2) node[left] {$B$} (orGate.out) node[right] {$A \text{ OR } B$} ; \end{circuitikz} $$
Rule: The OR gate output is 1 when any of the inputs is 1.
A | B | A OR B |
---|---|---|
0 | 0 | 0 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 1 |
$$ \begin{circuitikz} \draw (0,0) nodenand port {} (nandGate.in 1) node[left] {$A$} (nandGate.in 2) node[left] {$B$} (nandGate.out) node[right] {$A \text{ NAND } B$} ; \end{circuitikz} $$
Rule: The NAND gate output is 0 when all the inputs are 1
- The NAND gate is a NOT-AND gate
- The NAND gate can be viewed as a negative-OR whose output is 1 when any inputs is 0
$$ \begin{circuitikz} \draw (0,0) nodenor port {} (norGate.in 1) node[left] {$A$} (norGate.in 2) node[left] {$B$} (norGate.out) node[right] {$A \text{ NOR } B$} ; \end{circuitikz} $$
Rule: The NOR gate output is 0 when any of the inputs is 1.
- The NOR gate is a NOT-OR gate
- The NOR gate can be viewd as a negative-AND whose output is 1 only when all the inputs are 0.
$$ \begin{circuitikz} \draw (0,0) nodexor port {} (xorGate.in 1) node[left] {$A$} (xorGate.in 2) node[left] {$B$} (xorGate.out) node[right] {$A \text{ XOR } B$} ; \end{circuitikz} $$
Rule: The XOR gate output is 1 when all the inputs are not the same
$$ \begin{circuitikz} \draw (0,0) nodexnor port {} (xnorGate.in 1) node[left] {$A$} (xnorGate.in 2) node[left] {$B$} (xnorGate.out) node[right] {$A \text{ XNOR } B$} ; \end{circuitikz} $$
Rule: The XNOR gate output when the inputs are not the same
$$ \begin{circuitikz} \draw (0, 0) nodehalfAdder {HA} ; \end{circuitikz} $$
A half adder is a two input, two output circuit, that takes two input bits,
Truth table
0 | 0 | 0 | 0 |
1 | 0 | 0 | 1 |
0 | 1 | 0 | 1 |
1 | 1 | 1 | 0 |
Logic operations
$S = A \oplus B$ $C = AB$
Gate implementation
$$ \begin{circuitikz} \draw (4,2) nodexor port {} %xor gate (0,2.25) to[short](xorGate.in 1) %xor A wiring (0,1.75) to[short](xorGate.in 2) %xor B wiring (0,2.25) node[ocirc] {} %A node (0,2.25) node[left] {$A$} %A label (0,1.75) node[ocirc] {} %B node (0,1.75) node[left] {$B$} %B label (xorGate.out) toshort %S output wiring (5,2) node[ocirc] {} %S node (5,2) node[right] {$S$} %S label (4,0) nodeand port {} %AND gate (1,2.25) node[circ] {} (1.5,1.75) node[circ] {} (1.5,1.75) |- (andGate.in 1) (1,2.25) |- (andGate.in 2) (andGate.out) toshort %C output wiring (5,0) node[ocirc] {} %C node (5,0) node[right] {$C$} %C label ; \end{circuitikz} $$
$$ \begin{circuitikz} \draw (0, 0) nodefullAdder {} ; \end{circuitikz} $$
A full adder is a three input, two output circuit, that takes three input bits,
Truth table
0 | 0 | 0 | 0 | 0 |
1 | 0 | 0 | 0 | 1 |
0 | 1 | 0 | 0 | 1 |
1 | 1 | 0 | 1 | 0 |
0 | 0 | 1 | 0 | 1 |
1 | 0 | 1 | 1 | 0 |
0 | 1 | 1 | 1 | 0 |
1 | 1 | 1 | 1 | 1 |
Logic operations
$S = A \oplus B \oplus C_i$ $C_o = (A \cdot B) + (C_i \cdot (A \oplus B))$
Gate implementation
Full adder from two half adders A full adder can be implemented from two half adders and an OR gate:
$$ \begin{circuitikz} %Full adder from two half adders, Diego Trapero \draw (1.2, 0.0) nodehalfAdder {HA1} %HA1 (3.6, 0.0) nodehalfAdder {HA2} %HA2 (0.0, 0.5) nodeocirc {} (0.0, 0.5) node[left] {$A$} (0.0, 0.5) toshort (0.0, -0.5) nodeocirc {} (0.0, -0.5) node[left] {$B$} (0.0, -0.5) toshort (0.0, -1.5) nodeocirc {} (0.0, -1.5) node[left] {$C_i$} (HA1.S) toshort (HA2.S) to[short](6.6, 0.5) (6.0, -1.5) nodeor port {} (6.6, 0.5) nodeocirc {} (6.6, 0.5) node[right] {$S$} (6.6, -1.5) nodeocirc {} (6.6, -1.5) node[right] {$C_o$} (Ci) -| (HA2.B) (HA1.C) |- (OR.in 2) (HA2.C) |- (OR.in 1) (OR.out) -- (Co) ; \end{circuitikz} $$
1-bit equality comparator A 1 bit equality comparator can be implemented with a XNOR gate:
$$ \begin{circuitikz} \draw (0,0) nodexnor port {} (xnorGate.in 1) node[left] {$A$} (xnorGate.in 2) node[left] {$B$} (xnorGate.out) node[right] {$Y$} ; \end{circuitikz} $$
A | B | Y |
---|---|---|
0 | 0 | 1 |
0 | 1 | 0 |
1 | 0 | 0 |
1 | 1 | 1 |
A Multiplexer is...
2 to 1 Multiplexer
$$ \begin{circuitikz} \draw (0,0) node2to1MUX {} ; \end{circuitikz} $$
0 | 0 | 0 | 0 |
0 | 0 | 1 | 0 |
0 | 1 | 0 | 1 |
0 | 1 | 1 | 1 |
1 | 0 | 0 | 0 |
1 | 0 | 1 | 1 |
1 | 1 | 0 | 0 |
1 | 1 | 1 | 1 |
S | Y |
---|---|
0 | |
1 |
A straightforward realization of this 2-to-1 multiplexer would need 2 AND gates, an OR gate, and a NOT gate.
MUX implementation of truth table A mux based circuit can be used to implement a boolean function.
A logic function with
[***** poner ejemplo]
Biestables are devices that have two stable states (SET and RESET); they can retain either of these states indefininitly, making them useful as storage devices.
Latches are...
SR (SET-RESET) Latch
$$ \begin{circuitikz} \draw (0, 0) nodesrLatch {SRL} ; \end{circuitikz} $$
Gate implementations
$$ \begin{circuitikz} \draw (0, 1) nodenor port {} (0, -1) nodenor port {} ; \end{circuitikz} $$
Gated SR Latch
$$ \begin{circuitikz} \draw (0, 0) nodegsrLatch {} ; \end{circuitikz} $$
Gated D Latch
$$ \begin{circuitikz} \draw (0, 0) nodegdLatch {} ; \end{circuitikz} $$
Flip-flops are...
$$ \begin{circuitikz} \draw (0, 0) nodesrFlipFlop {} ; \end{circuitikz} $$
D FlipFlop
$$ \begin{circuitikz} \draw (0, 0) nodedFlipFlop {} ; \end{circuitikz} $$
$$ \begin{circuitikz} \draw (0, 0) nodedFlipFlop2x2 {} ; \end{circuitikz} $$
^ | 0 | 0 |
^ | 1 | 1 |
0 | X | Q |
1 | X | Q |
JK FlipFlop
$$ \begin{circuitikz} \draw (0, 0) nodejkFlipFlop {} ; \end{circuitikz} $$
Finite State Machines (FSM) are...
- Moore machine: The FSM uses only entry actions, i.e., output depends only on the state.
- Mealy machine: The FSM uses only input actions, i.e., output depends on input and state.
A Lookup Table (LUT) can enconde a
A
2-bit LUT
0 | 0 | |
0 | 1 | |
1 | 0 | |
1 | 1 |
FPGA logic cell FPGAs are built of many interconnected logic cells. A basic logic cell could be composed of a 4 LUT, a flipflop and a 2to1 mux to bypass the register.
$$ \begin{circuitikz} \draw (2,0) nodejkFlipFlop {$4LUT$} (5,-0.5) nodedFlipFlop2x2 {} (7,0) node2to1MUX {} (LUT.Q) -| (MUX.D0) (LUT.Q) -| (DFF.D) (DFF.Q) -| (MUX.D1) (0, 1) nodeocirc{} (0, 0.5) nodeocirc{} (0, 0) nodeocirc{} (0, -0.5) nodeocirc{} (0, -2.5) nodeocirc{} (0, -2) nodeocirc{} (S) -| (MUX.S) (CLK) -| (DFF.C) ; \end{circuitikz} $$
\newpage
\newpage
\tabulinesep=1mm \begin{longtabu} to\linewidth{|X[1,m,c]|X[1,m,c]|X[2,m,c]|X[2,m,c]|}
\hline
Gate & Symbol & Rule & Truth table \\
\hline
NOT
&
\begin{circuitikz} \draw (0,0) node[not port](notGate) {}; \end{circuitikz}
&
The NOT gate output is the complementary of the input
&
not
\\
\hline
AND
&
\begin{circuitikz} \draw (0,0) node[and port](andGate) {}; \end{circuitikz}
&
The AND gate output is 1 only when all the inputs are 1
&
and
\\
\hline
OR
&
\begin{circuitikz} \draw (0,0) node[or port](orGate) {}; \end{circuitikz}
&
The OR gate output is 1 when any of the inputs is 1
&
or
\\
\hline
NAND
&
\begin{circuitikz} \draw (0,0) node[nand port](nandGate) {}; \end{circuitikz}
&
The NAND gate output is 0 when all the inputs are 1
&
or
\\
\hline
NOR
&
NOR
\begin{circuitikz} \draw (0,0) node[nor port](norGate) {}; \end{circuitikz}
&
The NOR gate output is 0 when any of the inputs is 1
&
or
\\
\hline
XOR
&
\begin{circuitikz} \draw (0,0) node[xor port](xorGate) {}; \end{circuitikz}
&
The XOR gate output is 1 when all the inputs are not the same
&
or
\\
\hline
XNOR
&
\begin{circuitikz} \draw (0,0) node[xnor port](xnorGate) {}; \end{circuitikz}
&
The XNOR gate output when the inputs are not the same
&
or
\\
\hline
\end{longtabu}
\newpage
\tabulinesep=1mm \begin{longtabu} to\linewidth{X[1,m,c]X[1,m,c]}
\hline
Latch & asd \\
\hline
\begin{circuitikz} \draw (0,0) node[srLatch](notGate) {}; \end{circuitikz}
&
q
\\
\hline
\begin{circuitikz} \draw (0,0) node[gsrLatch](notGate) {}; \end{circuitikz}
&
q
\\
\hline
\begin{circuitikz} \draw (0,0) node[gdLatch](notGate) {}; \end{circuitikz}
&
q
\\
\hline
\end{longtabu}
\tabulinesep=1mm \begin{longtabu} to\linewidth{X[1,m,c]X[1,m,c]}
\hline
FlipFlop & asd \\
\hline
\begin{circuitikz} \draw (0,0) node[srFlipFlop](notGate) {}; \end{circuitikz}
&
q
\\
\hline
\begin{circuitikz} \draw (0,0) node[dFlipFlop](notGate) {}; \end{circuitikz}
&
q
\\
\hline
\begin{circuitikz} \draw (0,0) node[jkFlipFlop](notGate) {}; \end{circuitikz}
&
q
\\
\hline
\end{longtabu}
\newpage
- Digital Fundamentals, Thomas L. Floyd, 10th ed. Pearson
- https://en.wikipedia.org/wiki/Binary_number
- https://en.wikipedia.org/wiki/Ones'_complement