Digital Logic Design - Data Representation and Number Systems
Data Representation
- Data can be represented in various forms, including text, numbers, images, audio, and video.
- Text is represented using character encoding standards like ASCII, where each character is assigned a unique bit pattern.
- Example: The word \"BYTE\" is represented in ASCII code as \"1000010 1011001 1010100 1000101\".
- Images can be represented as bitmap or vector graphics.
- Bitmap graphics represent images as a matrix of pixels.
- Example: A black-and-white image can be represented using a matrix representation or a linear representation of bit patterns.
- Bitmap graphics represent images as a matrix of pixels.
- Color pixels are represented using color models like RGB (Red, Green, Blue).
- Each color component is assigned an intensity value.
- Example:
- Red (100% intensity): \"11111111 00000000 00000000\"
- Green (100% intensity): \"00000000 11111111 00000000\"
- Blue (100% intensity): \"00000000 00000000 11111111\"
- White (100% intensity): \"11111111 11111111 11111111\"
- Example:
- Each color component is assigned an intensity value.
- Audio is represented through sampling, quantization, and coding.
Number Systems
- Common Number Systems:
- Decimal (Base 10): Uses digits 0-9. Used by humans. Not used directly in computers.
- Binary (Base 2): Uses digits 0 and 1. Not used by humans. Used in computers.
- Octal (Base 8): Uses digits 0-7. Not used by humans. Not used directly in computers.
- Hexadecimal (Base 16): Uses digits 0-9 and letters A-F. Not used by humans. Not used directly in computers.
Quantities/Counting in Different Number Systems
| Decimal | Binary | Octal | Hexadecimal |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 1 | 1 | 1 | 1 |
| 2 | 10 | 2 | 2 |
| 3 | 11 | 3 | 3 |
| 4 | 100 | 4 | 4 |
| 5 | 101 | 5 | 5 |
| 6 | 110 | 6 | 6 |
| 7 | 111 | 7 | 7 |
| 8 | 1000 | 10 | 8 |
| 9 | 1001 | 11 | 9 |
| 10 | 1010 | 12 | A |
| 11 | 1011 | 13 | B |
| 12 | 1100 | 14 | C |
| 13 | 1101 | 15 | D |
| 14 | 1110 | 16 | E |
| 15 | 1111 | 17 | F |
| 16 | 10000 | 20 | 10 |
| 17 | 10001 | 21 | 11 |
Conversion Among Bases
- It's possible to convert between Decimal, Octal, Binary, and Hexadecimal number systems.
Quick Example of Base Conversion
Binary to Decimal Conversion
- Technique:
- Multiply each bit by , where n is the weight (position) of the bit, starting from 0 on the right.
- Add the results.
- Example:
Hexadecimal to Decimal Conversion
- Technique:
- Multiply each digit by , where n is the weight (position) of the digit, starting from 0 on the right.
- Add the results.
- Example:
Decimal to Binary Conversion
Binary Conversion Algorithm:
- Divide the value by two and record the remainder.
- As long as the quotient obtained is not zero, continue to divide the newest quotient by two and record the remainder.
- Once a quotient of zero has been obtained, the binary representation of the original value consists of the remainders listed from right to left in the order they were recorded.
Technique:
- Divide by two, keep track of the remainder.
- The first remainder is bit 0 (LSB - least-significant bit).
- The second remainder is bit 1, and so on.
Binary Conversion Example:
- , remainder 1
- , remainder 0
- , remainder 1
- , remainder 0
- , remainder 1
- Binary representation:
Example: Converting decimal 123 to binary.
- , remainder 1
- , remainder 1
- , remainder 0
- , remainder 1
- , remainder 1
- , remainder 1
- , remainder 1
- Result:
Hexadecimal to Binary Conversion
- Technique:
- Convert each hexadecimal digit to a 4-bit equivalent binary representation.
- Example:
- 1 = 0001
- 0 = 0000
- A = 1010
- F = 1111
Decimal to Hexadecimal Conversion
- Technique:
- Divide by 16 and keep track of the remainder.
- Example:
- , remainder 2
- , remainder 13 (D)
- , remainder 4
- Result:
Binary to Hexadecimal Conversion
- Technique:
- Group bits in fours, starting from the right.
- Convert each group of four bits to its equivalent hexadecimal digit.
- Example:
- 10 1011 1011
- 2 B B
Octal to Hexadecimal Conversion
- Technique:
- Use binary as an intermediary.
Common Powers
- Base 10:
| Power | Preface | Symbol | Value |
|---|---|---|---|
| pico | p | 0.000000000001 | |
| nano | n | 0.000000001 | |
| micro | µ | 0.000001 | |
| milli | m | 0.001 | |
| kilo | k | 1000 | |
| mega | M | 1000000 | |
| giga | G | 1000000000 | |
| tera | T | 1000000000000 |
- Base 2:
| Power | Preface | Symbol | Value |
|---|---|---|---|
| kilo | k | 1024 | |
| mega | M | 1048576 | |
| giga | G | 1073741824 | |
| tera | T | 1099511627776 |
In computing, particularly with memory, the base-2 interpretation generally applies.
Review – Multiplying Powers
- For common bases, add powers:
Binary Addition
- Two 1-bit values:
| A | B | A + B |
| :-: | :-: | :---: |
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 10 |
- Two n-bit values:
- Add individual bits.
- Propagate carries.
- Example:
- 10101 (21)
- 11001 (25)
- 101110 (46)
Multiplication
- Binary, two 1-bit values:
| A | B | A × B |
| :-: | :-: | :---: |
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
- Binary, two n-bit values:
- As with decimal values.
- Example:
- 1110 x 1011 = 10011010
Unsigned Binary Integers
- Y = \"abc\" = a \cdot 2^2 + b \cdot 2^1 + c \cdot 2^0
- Where the digits a, b, c can each take on the values of 0 or 1 only.
- N = number of bits
- Range is:
Signed Magnitude
- Leading bit is the sign bit
- Y = \"abc\" = (-1)^a(b \cdot 2^1 + c \cdot 2^0)
- Range is: -2^{N-1} + 1 < i < 2^{N-1} - 1
- Problems:
- How do we do addition/subtraction?
- We have two numbers for zero (+/-)!
- Not good!
One's Complement
- Invert all bits
- If MSB (most significant bit) is 1, then the number is negative (same as signed magnitude)
- Range is: -2^{N-1} + 1 < i < 2^{N-1} - 1
- Problems:
- Same as for signed magnitude
- Not good!
- Same as for signed magnitude
Two's Complement
- Transformation: To transform a into -a, invert all bits in a and add 1 to the result
- Range is: -2^{N-1} < i < 2^{N-1} - 1
- Advantages:
- Operations need not check the sign
- Only one representation for zero
- Efficient use of all the bits
Two’s Complement Calculation
- Calculate One's Complement
- Add 1
- Example -94:
- Get Binary Representation of 94: 01011110
- Produce One's Complement: 10100001
- Add 1: 10100010
Two's Complement Examples
- a. Using patterns of length three:
| Bit pattern | Value represented |
|---|---|
| 011 | 3 |
| 010 | 2 |
| 001 | 1 |
| 000 | 0 |
| 111 | -1 |
| 110 | -2 |
| 101 | -3 |
| 100 | -4 |
- b. Using patterns of length four:
| Bit pattern | Value represented |
|---|---|
| 0111 | 7 |
| 0110 | 6 |
| 0101 | 5 |
| 0100 | 4 |
| 0011 | 3 |
| 0010 | 2 |
| 0001 | 1 |
| 0000 | 0 |
| 1111 | -1 |
| 1110 | -2 |
| 1101 | -3 |
| 1100 | -4 |
| 1011 | -5 |
| 1010 | -6 |
| 1001 | -7 |
| 1000 | -8 |
Fractions
Binary to decimal:
Decimal to binary:
Logic Gates
- Logic gates are the building blocks used to create digital circuits.
- There are three elementary logic gates: AND, OR, and NOT, as well as other simple gates like NAND, NOR, XOR, and XNOR.
- Each gate has its own logic symbol, which allows complex functions to be represented by a logic diagram.
- The function of each gate can be represented by a truth table or using Boolean notation.
Elementary Logic Gates
AND:
- Output is 1 only if both inputs are 1.
- Truth Table:
| A | B | C (A AND B) |
| :-: | :-: | :-----------: |
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |- Boolean expression:
OR:
- Output is 1 if at least one input is 1.
- Truth Table:
| A | B | C (A OR B) |
| :-: | :-: | :----------: |
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |- Boolean expression:
NOT:
- Output is the inverse of the input.
- Truth Table:
| A | B (NOT A) |
| :-: | :-------: |
| 0 | 1 |
| 1 | 0 |- Boolean expression:
Other Logic Gates
NAND:
- Output is 0 only if both inputs are 1.
- Truth Table:
| A | B | C (A NAND B) |
| :-: | :-: | :------------: |
| 0 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |- Boolean expression:
NOR:
- Output is 1 only if both inputs are 0.
- Truth Table:
| A | B | C (A NOR B) |
| :-: | :-: | :-----------: |
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 0 |- Boolean expression:
XOR:
- Output is 1 if the inputs are different.
- Truth Table:
| A | B | C (A XOR B) |
| :-: | :-: | :----------: |
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |- Boolean expression:
Logic Gate Integrated Circuits (ICs)
- Examples of common logic gate ICs:
- 5400/7400: Quad NAND gate
- 5402/7402: Quad NOR gate
- 5408/7408: Quad AND gate
- 5432/7432: Quad OR gate
- 5486/7486: Quad XOR gate
- 5404/7404: Hex inverter
Flip-Flops
- Flip-flop = a circuit built from gates that can store one bit of data.
- Has an input line which sets its stored value to 1 (Set).
- Has an input line which sets its stored value to 0 (Reset).
- While both input lines are 0, the most recently stored value is preserved.
- 1s are not applied to both input lines simultaneously.