Digital Electronics Part 1: Binary Logic
Electronic devices in your everyday life What makes these products examples of electronic devices? What are some things they have in common? 2
How do electronics communicate and manipulate information? How do devices like computers interpret human commands? How do electronic systems store information? How do they manipulation information? 3
How do electronics communicate and manipulate information? How do devices like computers interpret human commands? Humans provide inputs through keyboards, mice, touchscreens, knobs, etc. Each of these inputs is built into the circuit Example: calculator circuit shown in the image How do electronic systems store information? Circuits can have different states based on whether: switches are on/off knobs are turned high/low voltages are high/low... How do electronic systems manipulate information? Logic is built into the circuit We will discuss this more shortly 4
Programs stored in computer memory Some electronics can be programmed to perform new tasks without rewiring. Humans provide instructions to computers using high-level languages (like Python, C, Java, Ruby, ), which are then translated into machine language. Machine language is often in binary a number system that only uses 0 and 1. Why binary? What do these 1s and 0s represent? High-level programming language Machine language 5
Binary (Base 2) 6
Why use binary? Binary is a way to represent numbers using only 0 and 1. It s relatively easy and cheap to make circuit components that are either on or off (a two-state device). Computers are a combination of many, many such devices. 7
Data size You are likely familiar with file sizes: kilobytes, megabytes, etc. What do those sizes represent? Each binary digit (0 or 1) is called a bit (b). A group of 8 bits is called a byte (B). A group of 1000 bytes is a kilobyte (KB). A group of 10 6 bytes is a megabyte (MB). A group of 10 9 bytes is a gigabyte (GB). 8
What is binary? Binary is a way to represent numbers using only 0 and 1. You are accustomed to the decimal system, which is base 10. There are 10 digits that represent all numbers (0, 1, 2, 3, 4, 5, 6, 7, 8, and 9). Binary is base 2, so it only has 2 digits (0 and 1). Consider the decimal system (base 10). What does each digit represent? 512 = 5 x 10 2 + 1 x 10 1 + 2 x 10 0 512 = 5 x 100 + 1 x 10 + 2 x 1 Binary is base 2. Only digits are 0 and 1. Each digit in a number represents a power of 2. To distinguish between decimal and binary numbers, use 0b before the digits or use subscript 2 at the end. 10101 2 = 0b10101 = 1 x 2 4 + 0 x 2 3 + 1 x 2 2 + 0 x 2 1 + 1 x 2 0 What decimal number is 10101 2 equal to? = 1 x 16 + 0 x 8 + 1 x 4 + 0 x 2 + 1 x 1 9
Quiz: binary and decimal 1. What is the largest decimal number we can represent with 8 binary digits? 2. How many binary digits do we need to represent the decimal number 55? 3. Which of these numbers are even? a. 100 2 b. 1100 2 c. 1000001 2 d. 011101011 2 4. Convert 0b110100 from binary to decimal. 5. Convert 123 from decimal to binary. 10
Limitations of binary Precision limitations, especially when we consider decimal and negative values Ex: How many bits are needed to represent a number between 0.00 10.00? Discrete vs continuous (digital vs analog). Only limited number of buckets conversion from analog to digital sometimes loses information. (example above is rounded to two decimal places) 11
Analog vs digital Analog - Continuous Digital - Discrete Examples: Mercury thermometers Phonographs (vinyl records) Scale that uses a sliding weight Examples: Digital thermometer CDs Digital scale Benefits: Could have an infinite number of values May be higher quality (e.g. original painting vs digital photogram) Benefits: Can be stored and manipulated by computers Values are less ambiguous: If data starts to degrade, it may be possible to recover it Digital circuits are less susceptible to noise 12
Binary, octal, and hexadecimal Binary is base 2. Digits are 0 and 1. Each digit represents a power of 2. 10101 2 = 1 x 2 4 + 0 x 2 3 + 1 x 2 2 + 0 x 2 1 + 1 x 2 0 = 21 Octal is base 8. Digits are 0, 1, 2, 3, 4, 5, 6, 7. Each digit represents a power of 8. 25 8 = 2 x 8 1 + 5 x 8 0 = 21 Hexadecimal is base 16. Digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F Each digit represents a power of 16. 15 16 = 1 x 16 1 + 5 x 16 0 = 21 13
ASCII table Characters can be converted to numbers using conventions like the ASCII table. 14
Converting from binary to octal or hexadecimal Binary to octal group 3 bits (add leading zeros if needed) 10101 2 10 101 2 = 25 8 010 2 = 2 101 2 = 5 Binary to hexadecimal group 4 bits (add leading zeros if needed) 10101 2 1 0101 2 = 15 16 0001 2 = 1 0101 2 = 5 15
Digital Boolean Logic 16
Analogy between devices, binary values, logic, and circuits In the following discussion we consider two-state inputs or outputs. Depending on the context, it may be helpful to consider the two options as off vs. on or false vs. true. Device Off On Binary 0 1 Logic False True Physical circuit Low voltage High voltage 17
Logic: AND Consider a device that should only perform an action (say, turn on a light) when Switch A and Switch B are both activated. What would that circuit look like? Lightbulb 1 2 AND Power supply Switch 1 Switch 2 Light Off Off Off On On Off On On 18
Logic: OR Consider a device that should only perform an action (say, turn on a light) when either Switch A or Switch B is activated. What would that circuit look like? Lightbulb 1 2 OR Power supply Switch 1 Switch 2 Light Off Off Off On On Off On On 19
Logic: NOT Consider a device that should only perform an action (say, turn on a light) when Switch A is not activated. What would that circuit look like? Lightbulb 1 NOT Switch 1 Off On Light Power supply 20
Logic gates: AND Logic gates are idealized representations of the AND, OR, and NOT actions you built with simple circuits. They are an abstract way to connect circuit inputs to circuit outputs. Switch 1 value Switch 2 value AND Lightbulb value 1 2 AND Input 1 Input 2 AND Output Switch 1 Switch 2 Light Off Off Off Off On Off On Off Off On On On Input 1 Input 2 Output Off Off Off Off On Off On Off Off On On On 21
Logic gates Input 1 Input 2 AND Output Input 1 Input 2 OR Output Input 1 Input 2 Output Off Off Off Off On Off On Off Off On On On Input 1 Input 2 Output Off Off Off Off On On On Off On On On On Input NOT Output Input Off On Output On Off 22
Logic gates Input 1 Input 2 AND Output Input 1 Input 2 OR Output Input 1 Input 2 Output Off Off Off Off On Off On Off Off On On On Input 1 Input 2 Output Off Off Off Off On On On Off On On On On Input 1 Input 2 NAND Output Input 1 Input 2 NOR Output Input 1 Input 2 Output Off Off On Off On On On Off On On On Off Input 1 Input 2 Output Off Off On Off On Off On Off Off On On Off 23
Integrated circuits Physically, logic gates are composed of transistors or diodes that act as switches, and they are often manufactured as part of integrated circuits. Notch Complementary metal-oxide-semiconductor (CMOS) devices (shown in the photo) are examples of integrated circuits. Example schematic 24