Lecture 3 - Binary System and Logic Gates.pdf
Document Details
Uploaded by DazzlingTurtle
King Saud University
Tags
Full Transcript
Fundamentals & Ethics of Information Systems IS 201 Lecture 3 Binary Number System and Logic Gates Lecture 3 – Binary System and Logic Gates Learning Objectives 1. Know the different types of number systems 2. Describe positional numbe...
Fundamentals & Ethics of Information Systems IS 201 Lecture 3 Binary Number System and Logic Gates Lecture 3 – Binary System and Logic Gates Learning Objectives 1. Know the different types of number systems 2. Describe positional number notation 3. Convert base 10 numbers into numbers of other bases and vice versa 4. Describe the relationship between bases 2, 8, and 16 5. Identify the basic Boolean logic operations 6. Identify the basic gates and describe the behavior of each using Boolean expressions and truth tables 7. Explain how a Boolean expression can be converted into circuits Lecture 3 – Binary System and Logic Gates Chapter Overview 1. The Importance of Learning the Binary System 2. Number Systems 3. Conversions from the Decimal System to Other Systems 4. Converting Binary to Octal and Hexadecimal 5. Binary Arithmetic 6. Fixed-Point and Floating-Point Number Representations 7. Boolean Algebra 8. Logic Gates 9. Building Computer Circuits 10. Summary Lecture 3 – Binary System and Logic Gates 1. The Importance of Learning the Binary System ◼ Modern computer systems do not represent numeric values using the decimal system. ◼ Computers use a binary or two's complement numbering system. ◼ Learning the binary system helps you to understand how the basic operations (e.g., addition) of the processor are done. ◼ To be aware of the limitations of computer arithmetic, you must understand how computers represent numbers. Lecture 3 – Binary System and Logic Gates 2. Number Systems ◼ There are four number bases commonly used in programming. Name Base Digits Symbol Binary 2 0,1 (N)2 Octal 8 0,1,2,3,4,5,6,7 (N)8 Decimal 10 0,1,2,3,4,5,6,7,8,9 (N)10 Hexadecimal 16 0,..,9,A,B,C,D,E,F (N)16 Lecture 3 – Binary System and Logic Gates Decimal Number System ◼ The Decimal Number System uses base 10. It includes the digits from 0 through 9. The weighted values for each position is as follows: 104 103 102 101 100 10-1 10-2 10-3 10000 1000 100 10 1.1.01.001 ◼ When you see a number like "123", you don't think about the value 123. Instead, you generate a mental image of how many items this value represents. In reality, the number 123 represents: 1 * 102 + 2 * 101 + 3 * 100 = 1 * 100 + 2 * 10 + 3 * 1 = 100 + 20 + 3 = 123 Lecture 3 – Binary System and Logic Gates Decimal Number System (Cont.) ◼ Each digit appearing to the left of the decimal point represents a value between zero and nine times power of ten represented by its position in the number. ◼ Digits appearing to the right of the decimal point represent a value between zero and nine times an increasing negative power of ten. ◼ For example, the value 725.194 is represented as follows: 7*102 + 2*101 + 5*100 + 1*10-1 + 9*10-2 + 4*10-3 = 7*100 + 2*10 + 5*1 + 1*0.1 + 9*0.01 + 4*0.001 = 700 + 20 + 5 + 0.1 + 0.09 +.0004 = 725.194 Lecture 3 – Binary System and Logic Gates Binary Number System ◼ The smallest "unit" of data on a binary computer is a single bit. ◼ Electronic components like transistors have a digital nature. ◼ They can be either in an "on" state or an "off" state, representing binary 1 and 0, respectively. ◼ The binary number system operates similarly to the decimal system, but with a base of 2. In binary, only the digits 0 and 1 are used. 0,1 ◼ The weighted values for each position is determined as follows: 27 26 25 24 23 22 21 20 2-1 2-2 128 64 32 16 8 4 2 1.5.25 Lecture 3 – Binary System and Logic Gates Binary to Decimal ◼ Let’s convert the following two binary numbers to decimal numbers: 10011 and 1101.01 10011= 1*24 + 0*23 + 0*22 + 1*21 + 1*20 = 1*16 + 0*8 + 0*4 + 1*2 + 1*1 = 16 + 0 + 0 + 2 + 1 = 19 1101.01= 1*23 + 1*22 + 0*21 + 1*20 + 0*2-1 + 1*2-2 = 1*8 + 1*4 + 0*2 + 1*1 + 0*.5 + 1*.25 = 8 + 4 + 0 + 1 +.25 = 13.25 Lecture 3 – Binary System and Logic Gates Octal Number System ◼ The octal number system uses base 8 and includes only the digits 0 through 7: 0,1,2,3,4,5,6,7 ◼ The weighted values for each position is as follows: 85 84 83 82 81 80 32768 4096 512 64 8 1 Lecture 3 – Binary System and Logic Gates Octal to Decimal ◼ Let’s convert the following two octal numbers to decimal numbers: 736 and 670.32 736= 7*82 + 3*81 + 6*80 = 7*64 + 3*8 + 6*1 = 448 + 24 + 6 = 478 670.32= 6*82 + 7*81 + 0*80 + 3*8-1 + 2*8-2 = 6*64 + 7*8 + 0*1 + 3*.125 + 2*.015625 = 440.40625 Lecture 3 – Binary System and Logic Gates Hexadecimal Number System ◼ The Hexadecimal Number System uses base 16 and includes the digits 0 through 9 and the letters A, B, C, D, E, and F: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E, and F ◼ The weighted values for each position is as follows: 163 162 161 160 4096 256 16 1 Lecture 3 – Binary System and Logic Gates Hex to Decimal ◼ To convert from Hex to Decimal, multiply each hex digit by its weight and add the results. 0AFB2 = A*163 + F*162 + B*161 + 2*160 = 10*4096 + 15*256 + 11*16 + 2*1 = 40960 + 3840 + 176 + 2 = 44978 Lecture 3 – Binary System and Logic Gates 3. Conversion of Decimal Numbers ◼ Decimal to Binary Conversion ◼ Decimal to Octal conversion ◼ Decimal to Hexadecimal system Lecture 3 – Binary System and Logic Gates Decimal to Binary ◼ This method consists of two steps: ◼ Step 1 ◼ Dividing the integer part by 2 repeatedly until its value becomes 0, while keeping track of the remainder R at each division. ◼ Step 2 ◼ Concatenate the remainders from the least significant bit (LBS) at the top to the most significant bit (MSB) at the bottom. ◼ Write the number from right to left. Lecture 3 – Binary System and Logic Gates Decimal to Binary (Cont.) ◼ Converting the decimal number 18 into the binary system. Number/Base Integer Part Remainder Remark 18 /2 9 0 LSB 18 = 2 * 9 + 0 9 /2 4 1 9=2*4 + 1 4 /2 2 0 4=2*2 + 0 2 /2 1 0 2=2*1 + 0 1 /2 0 1 MSB 1 = 2 * 0 + 1 ◼ Thus, 1810 = 100102 Lecture 3 – Binary System and Logic Gates Decimal to Octal ◼ The same method is applied in this case except that we will perform successive divisions by 8 ◼ Why divide by 8? Because the base of the octal system is 8 ◼ Example: Translating the decimal number 18 into the octal system. Number/Base Integer Part Remainder Remark 18 /8 2 2 18 = 8 * 2 + 2 2 /8 0 2 2=8*0 + 2 ◼ Thus, 1810 = 228 Lecture 3 – Binary System and Logic Gates Decimal to Hexadecimal ◼ The same method is applied in this case except that we will perform successive divisions by 16 ◼ Why divide by 16? Because the base of the hexadecimal system is 16 ◼ Example: Translating the decimal number 18 into the hexadecimal system. Number/Base Integer Part Remainder Remark 18 /16 1 2 18 = 16 * 1 + 2 1 /16 0 1 1 = 16 * 0 + 1 ◼ Thus, 1810 = 1216 Lecture 3 – Binary System and Logic Gates 4. Conversion of Binary Numbers ◼ A major problem with the binary system is the large number of digits needed to represent even small values. ◼ To represent 20210, eight binary digits are needed, compared to only three in the decimal system. ◼ When dealing with large numeric values, binary numbers quickly become unmanageable. ◼ The hexadecimal (base 16) numbering system solves this issue with two key features: ◼ Compact representation. ◼ Simple conversion between hex and binary, and vice versa. Lecture 3 – Binary System and Logic Gates Uses of the Hexadecimal System ◼ Color representation ◼ 165D31 :اللون االخضر في العلم السعودي يمكن تمثيله كالتالي Red:16, Green:5D, Blue:31 ◼ https://www.color-hex.com/ ◼ MAC (physical) addresses ◼ 00:1A:2B:3C:4D:5E ◼ Character encoding standards ◼ "IS201" equals 49 53 32 30 31 in UTF-8 ◼ URL encoding ◼ "%20" in URLs signifies the space character in UTF-8 Lecture 3 – Binary System and Logic Gates Converting Binary Numbers 1. Converting Binary to Octal 2. Converting Binary to Hexadecimal Lecture 3 – Binary System and Logic Gates Binary to Octal ◼ Convert 10101011 2 into octal 1. First, group the binary digits into sets of three from right to left 10 101 011 2. Then, for each group, multiply each digit with 2x where x is incremented from 0 to 2 from right to left 10 101 011 21 20 22 21 20 22 21 20 3. Finally, sum the numbers for each group 2 5 3 ◼ 10101011 is 253 in base 8 Lecture 3 – Binary System and Logic Gates 17 Octal to Binary ◼ Convert 718 into binary ◼ Transform each octal digit into a 3-digit binary number, starting from the right. 7 1 111 001 ◼ 718 is 1110012 Lecture 3 – Binary System and Logic Gates 17 Binary to Hexadecimal ◼ Convert 10101011 2 into hexadecimal 1. First, group the binary digits into sets of four from right to left 1010 1011 2. Then, for each group, multiply each digit with 2x where x is incremented from 0 to 3 from right to left 1010 1011 2 3 22 21 20 23 22 21 20 3. Finally, sum the numbers for each group ◼ Therefore, 10101011 2 is AB16 Lecture 3 – Binary System and Logic Gates 18 Hexadecimal to Binary ◼ Convert 𝐴116 into binary ◼ Transform each hex digit into a 4-digit binary number, starting from the right. Remember that A=10 A 1 1010 0001 ◼ 𝐴116 is 101000012 Lecture 3 – Binary System and Logic Gates 17 Exercises 1. Convert the following numbers into decimal numbers ◼ (00000001)2, (00000111)2, (010011.11)2, (011010.10)2 ,(68)8, (E4)16 2. Convert the following numbers into octal and hex ◼ (00000001)2, (00101111)2, (00010011)2, (11011010)2 3. Convert the following numbers into binary numbers. Write your answer using 8 digits (8 bits) ◼ (0)10, (10)10, (56)10, (169)10 4. Convert the following numbers into binary numbers. ◼ (135)8, (021)8, (703)8 ◼ (135)16, (021)16, (0A1)16, (0E)16 ◼ Check your answers using the following tool: [link] Lecture 3 – Binary System and Logic Gates Limitations of Computer Arithmetic ◼ Binary representation encounters difficulties with certain non-integer values like 0.110 , 0.310 , and 0.5510 ◼ These numbers are easily represented in the decimal system. ◼ But they become non-terminating in binary (i.e., infinite binary fractions). link ◼ Exercise: Using the following tool [link], compare the conversion into binary of 3.510 and 3.5510. ◼ 3.5510 is more challenging to represent in binary ◼ Rounding is often employed to deal with these challenges. However, it introduces errors in certain cases. link ◼ Exercise: In python, try 0.2+0.1 [link] Lecture 3 – Binary System and Logic Gates Limitations of Computer Arithmetic⁺ ◼ Highly recommended video: https://www.youtube.com/watch?v=PZRI1IfStY0 ◼ Rounding off errors in Java: https://www.geeksforgeeks.org/rounding-off-errors-java/ Lecture 3 – Binary System and Logic Gates 5. Binary Arithmetic 1. Binary Addition 2. Binary Subtraction Lecture 3 – Binary System and Logic Gates Addition ◼ In the binary system, there are four addition cases taking into account the digits 0 and 1 and the possible carry: Operation carry result 0+0 0 0 0+1 0 1 1+1 1 0 1+1+1 1 1 Lecture 3 – Binary System and Logic Gates Addition (Cont.) ◼ Perform the addition of the following binary numbers: 110010 and 100111 Carry values 11 110010 + 100111 1011001 Lecture 3 – Binary System and Logic Gates Subtraction ◼ The CPU doesn't perform subtraction in the same way humans do, but rather uses addition with two's complement representation to achieve subtraction operations. ◼ Complement operations are the method used to represent negative numbers. ◼ Example, the following operation 7-4 is reformulated as 7+(-4), where the negative term is represented using two's complement notation. Lecture 3 – Binary System and Logic Gates Negative Numbers in Binary ◼ Signed magnitude ◼ One’s complement ◼ Two’s complement Lecture 3 – Binary System and Logic Gates Signed Magnitude ◼ In signed magnitude representation, the leftmost bit is the sign bit (0 for positive, 1 for negative). ◼ The remaining bits represent the magnitude of the number ()قيمة الرقم. ◼ Example: ◼ 7 in signed magnitude: 0000 0111 ◼ -7 in signed magnitude: 1000 0111 ◼ Limitation: Cannot perform arithmetic operations directly ◼ Try 7+(-3) ◼ 7+(-3) = 0111+(-0011) = 0111+1011 = 0010 ◼ The result is incorrect Lecture 3 – Binary System and Logic Gates One’s Complement ◼ In one's complement, negative numbers are represented by inverting all the bits of the corresponding positive number. ◼ Example: ◼ 5 in one's complement (8-bit): 0000 0101 ◼ −5 in one's complement (8-bit): 1111 1010 (Inverted bits of +5) ◼ Limitation: Cannot perform arithmetic operations directly ◼ Try 7+(-3) ◼ 7+(-3) = 0111+(-0011) = 0111+1100 = 0011 ◼ The result is incorrect Lecture 3 – Binary System and Logic Gates Two’s Complement ◼ In two's complement, negative numbers are represented by: ◼ Inverting all the bits of the corresponding positive number. ◼ Adding 1 to the result. ◼ Example: ◼ 7 in two's complement (8-bit): 0000 0111 ◼ −7 in two's complement (8-bit): 1111 1001 (Invert 0000 0111 then add 1) ◼ Two's complement performs arithmetic operations accurately. ◼ Try 7-3 ◼ 7+(-3) = 0111+(-0011) = 0111+1101 = 0100 Lecture 3 – Binary System and Logic Gates Exercises 1. Perform the following binary operations ◼ 11 + 11, 1101.10 + 111, 11111 + 100011 2. Perform the following operation using two’s complement ◼ (44 - 13)10 [solved in this link] 3. Using two’s complement, convert (- 43)10 into binary. Write your answer using 8 digits. [solved in this link] 4. Convert (1111 1000)2 ,represented in two’s complement, into decimal. ◼ The leftmost bit is 1, therefore it’s a negative number ◼ Invert the binary bits, add one ◼ Then convert to decimal ◼ The final result is (- 8)10 Lecture 3 – Binary System and Logic Gates Exercises 5. Considering the binary number (1111 1000)2 represented in two’s complement, is it a positive or negative number? ◼ Negative, because the MSB is 1 6. Considering the binary number (0111 1000)2 represented in two’s complement, is it a positive or negative number? ◼ Positive, because the MSB is 0 Lecture 3 – Binary System and Logic Gates Exponential Growth in Value Representation: 4-bit vs. 8-bit ◼ 4-bit Representation: ◼ With 4 bits, we can represent 2^4 = 16 unique values. ◼ These values range from 0000 to 1111 in binary, or 0 to 15 in decimal. ◼ 8-bit Representation: ◼ With 8 bits, we can represent 2^8 = 256 unique values. ◼ These values range from 00000000 to 11111111 in binary, or 0 to 255 in decimal. ◼ Transitioning from 4-bit to 8-bit representation results in an exponential increase in the number of possible values. Lecture 3 – Binary System and Logic Gates Addressing Limitations in 32-bit Systems ◼ 32-bit Systems: ◼ Memory addresses are represented by 32 bits, allowing for a total of 2^32 (=4 Giga) unique addresses, resulting in a maximum addressable memory of approximately 4GB. ◼ 64-bit Systems: ◼ With 2^64 unique addresses, 64-bit systems can theoretically address up to 16 exabytes (EB) of memory. ◼ The increase of unique memory addresses from 32 to 64 bits is exponential, not linear ◼ With each additional bit, the addressable memory space doubles. ◼ The transition from 32-bit to 64-bit systems overcomes the memory limitations of the 32-bit systems. Lecture 3 – Binary System and Logic Gates 6. FIXED-POINT AND FLOATING- POINT NUMBER REPRESENTATIONS Lecture 3 – Binary System and Logic Gates Fixed-Point Representation ◼ Represents numbers with a fixed number of digits after the decimal point. ◼ Example: 1010.1000 is a fixed-point number with 4 integer bits and 4 fractional bit. ◼ Integer= 1010, Fraction = 1000 ◼ Disadvantage: Limited range and precision compared to floating-point representation. Lecture 3 – Binary System and Logic Gates Fixed Point Representation of Negative Number ◼ Negative numbers in fixed-point representation are typically represented using signed representation and two's complement notation. ◼ Signed representation: ◼ Let's consider the number -14.25 and represent it in fixed-point binary using 5 bits for the integer and 3 bits for the fraction. ◼ 14.25 = 01110.010 => -14.25= 11110.010 ◼ Two’s complement: ◼ 14.25 = 01110.010 => (invert and add 1) -14.25= 10001.110 Lecture 3 – Binary System and Logic Gates Floating-Point Representation ◼ It represents numbers as a scientific notation (as in 1.010101001x 2^6), allowing a variable number of digits before and after the decimal point. ◼ It consists of three parts: sign bit, exponent, and fraction. sign e ponent (8 bits fraction ( bits 0 0 1 1 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 01 1 0 (bit inde 0 ◼ Example: 85.125 ◼ 8510 = 10101012 and 0.12510 = 0012 ◼ 85.12510 = 1010101.0012 = 1.010101001 x 2^6 ◼ Fraction= 010101001, Exponent = 6, Sign = 0 ◼ The representation involves more details, but here we're just providing a basic explanation. Lecture 3 – Binary System and Logic Gates Range of Values: Fixed-Point vs Floating-Point ◼ Let's compare the range expansion using 32 bits for both fixed-point and floating-point representations ◼ For the fixed-point, if we allocate 16 bits for the integer part and 16 bits for the fractional part, the range of representable numbers would be from −32,768.9999847412109375 to 32,767.9999847412109375 ◼ The range of numbers in floating-point (using the IEEE 754 single-precision format) is approximately from ±1.175 × 10−38 to ±3.403 × 1038 Lecture 3 – Binary System and Logic Gates Character Encoding: ASCII ◼ ASCII (American Standard Code for Information Interchange) is developed in the early days of computing. ◼ Uses 7 bits to represent 128 characters, including ◼ Uppercase and lowercase letters (A-Z, a-z) ◼ Numbers (0-9) ◼ Common punctuation marks (!, ?, :, etc.) ◼ Control characters (spacing, backspace, and carriage return, etc.) ◼ Example ◼ In ASCII, 'A' is represented as 01000001. ◼ Limitation: ASCII represents English letters only. Lecture 3 – Binary System and Logic Gates Character Encoding: Extended ASCII ◼ Extended ASCII extends the basic ASCII set by utilizing 8 bits, thus accommodating an additional 128 characters. ◼ 128 characters from ASCII + additional 128 characters = 256 ◼ The additional characters are usually of a specific language such as Arabic, Turkish, and Thai. [link] ◼ Unlike ASCII, Extended ASCII lacks a unified standard. ◼ Consequently, compatibility issues arise. ◼ For example, when a system that uses Latin/Arabic interacts with another system that uses Latin/Turkish. Lecture 3 – Binary System and Logic Gates Character Encoding: UTF-8 ◼ UTF-8 (Unicode Transformation Format) ◼ Uses a flexible system to represent characters from almost any language, including emojis! ◼ A variable-length encoding. ◼ UTF-8 uses one to four bytes to represent characters. ◼ Encodes more than 1.1 million characters. ◼ The first 100,000 characters in UTF-8 [link] ◼ In theory, it’s capable of encoding more than a billion characters! Lecture 3 – Binary System and Logic Gates Character Encoding: UTF-8 ◼ UTF-8 is efficient and backward compatible with ASCII ◼ By using one byte for ASCII characters, UTF-8 ensures backward compatibility For instance, the space character (' ' retains its ASCII representation (00100000 in UTF-8 ◼ UTF-8 handles special characters that aren’t in ASCII ◼ These less common characters are represented using multiple bytes in UTF-8 ◼ E amples: ◼ The Euro sign ('€' is encoded as 11100010 10000010 10101100 ◼ is encoded as 11100010 10011000 10111010 Lecture 3 – Binary System and Logic Gates Optional Resources⁺ ◼ How does the UTF-8 work? ◼ https://www.youtube.com/watch?v=MijmeoH9LT4 ◼ https://symbl.cc/en/ Lecture 3 – Binary System and Logic Gates 7. Boolean Algebra ◼ Why computers use the binary system? 1. Electronic components like transistors have a digital nature. They can be either in an "on" state or an "off" state, representing binary 1 and 0, respectively. 2. An entire branch of mathematics already existed that dealt exclusively with true and false values. Lecture 3 – Binary System and Logic Gates Boolean Algebra Components ◼ The set of Boolean values {F,T} ◼ Boolean variables a, b, …∈ {F,T} ◼ Boolean operations {AND, OR, NOT} ◼ Boolean expressions ◼ Boolean functions Lecture 3 – Binary System and Logic Gates Boolean Operations ◼ a AND b ◼ True only when a is true and b is true ◼ a OR b ◼ True when a is true, b is true, or both are true ◼ NOT a ◼ True when a is false and vice versa Lecture 3 – Binary System and Logic Gates Boolean Expressions ◼ Constructed by combining together Boolean operations and variables ◼ Example: (a AND b) AND c a b c a AND b (a AND b) AND c F F F F F F F T F F F T F F F F T T F F T F F F F T F T F F T T F T F T T T T T Lecture 3 – Binary System and Logic Gates 8. Logic Gates ◼ Gates are hardware devices built from transistors to mimic Boolean Operations ◼ Gates are made of transistors (see next slides) ◼ Transistors are made of semiconductor materials ◼ Types of materials based on their conductivity: ◼ Conductors: copper and aluminum ◼ Insulators: rubber, glass, and plastic ◼ Semiconductors: silicon and germanium ◼ What is A Semiconductor: https://www.youtube.com/watch?v=gUmDVe6C-BU (0:00 to 1:26) Lecture 3 – Binary System and Logic Gates AND Gate Source: The Crash Course Computer Science Lecture 3 – Binary System and Logic Gates AND Gate Source: The Crash Course Computer Science Lecture 3 – Binary System and Logic Gates AND Gate Source: The Crash Course Computer Science Lecture 3 – Binary System and Logic Gates OR Gate Source: The Crash Course Computer Science Lecture 3 – Binary System and Logic Gates OR Gate Source: The Crash Course Computer Science Lecture 3 – Binary System and Logic Gates OR Gate Source: The Crash Course Computer Science Lecture 3 – Binary System and Logic Gates OR Gate Source: The Crash Course Computer Science Lecture 3 – Binary System and Logic Gates Moore's Law: Observing Exponential Growth in Computing Power ◼ Moore's Law ◼ It states that the number of transistors on a microchip doubles approximately every two years, leading to exponential growth in computing power and technological advancement. ◼ How? ◼ Transistors are getting smaller over time. ◼ Transistors are also becoming more Photo by Shigeru23 / CC BY power-efficient. Lecture 3 – Binary System and Logic Gates Logic Gates (cont.) ◼ Boolean values (F,T) ----- signal value (0,1) ◼ Boolean operations ----- logic gates ◼ Boolean function ------ logic circuit Lecture 3 – Binary System and Logic Gates Three Basic Gates Basic Gates Symbols Truth Tables The Three Basic Gates, Their Symbols and Truth Tables Lecture 3 – Binary System and Logic Gates 9. Building Computer Circuits ◼ A circuit is a collection of logic gates ◼ Transforms a set of binary inputs into a set of binary outputs ◼ Values of the outputs depend only on the current values of the inputs Diagram of a Typical Computer Circuit Lecture 3 – Binary System and Logic Gates The Design Process of Compare-for-Equality Circuit ◼ Problem specification ◼ Define the function and specify the number of inputs and outputs. ◼ Truth table generation ◼ The table lists all possible combinations of input values and their corresponding output values. ◼ Logic expression derivation ◼ Simplification of logic expression ◼ Logic circuit design Lecture 3 – Binary System and Logic Gates CE: Problem Specification ◼ Compare-for-equality compares two binary numbers for equality. ◼ For example, let A= 1001 and B= 1010, is A equals B? ◼ Built by combining together 1-bit comparison circuits (1-CE) ◼ A circuit for the first digit, and another circuit for the second digit, etc ◼ A and B are equal if corresponding bits are equal. Lecture 3 – Binary System and Logic Gates 1-CE: Truth Table Generation a b F 0 0 1 Truth table captures every 0 1 0 input/output 1 0 0 possible for circuit 1 1 1 Lecture 3 – Binary System and Logic Gates 1-CE: Logic Expression Derivation 1. For each line with output 1 in the truth table, build a product term using AND and NOT 2. Combine together all product terms with ORs a b F 0 0 1 0 1 0 1 0 0 1 1 1 Lecture 3 – Binary System and Logic Gates 1-CE: Logic Expression Derivation 1. For each line with output 1 in the truth table, build a product term using AND and NOT 2. Combine together all product terms with ORs a b F 0 0 1 Writing a Logic0Expression 1 From 0 a Truth Table https://www.youtube.com/watch?v=uZel7wLztM0 1 0 0 1 1 1 Lecture 3 – Binary System and Logic Gates 1-CE: Simplification of Logic Expression ◼ This expression can be minimized/simplified, but we won't address that process here. ◼ Examples of minimization can be found in Slide 71 and Slide 75 Lecture 3 – Binary System and Logic Gates 1-CE: Logic Circuit Design ◼ From this expression , we design the circuit Lecture 3 – Binary System and Logic Gates 4-CE Circuit a0 A and B are equal b0 1-CE if corresponding bits are equal a1 b1 1-CE AND F gate a2 1-CE b2 a3 b2 1-CE Lecture 3 – Binary System and Logic Gates Exercise 1 ◼ Find the output of the following circuit x y y Lecture 3 – Binary System and Logic Gates Exercise 1: Solution ◼ Find the output of the following circuit x 𝒙+𝒚 y (𝒙 + 𝒚)ഥ 𝒚 ഥ 𝒚 y ◼ ഥ Answer: 𝒙 + 𝒚 ∙ 𝒚 Lecture 3 – Binary System and Logic Gates Order of Boolean Operations 1. Parentheses 2. NOT 3. AND 4. OR Lecture 3 – Binary System and Logic Gates Exercise 2 ◼ Find the output of the following circuit x y Lecture 3 – Binary System and Logic Gates Exercise 2: Solution ◼ Find the output of the following circuit ഥ 𝒙 x ഥ∙𝒚 𝒙 ഥ ഥ∙𝒚 𝒙 ഥ ഥ 𝒚 y ◼ ഥ∙𝒚 Answer: 𝒙 ഥ =𝒙+𝒚 Lecture 3 – Binary System and Logic Gates Exercise 3 ◼ Design the circuits for the following Boolean algebraic expression: 𝑥ҧ + 𝑦 ◼ Solution: ഥ 𝒙 x ഥ+𝒚 𝒙 y Lecture 3 – Binary System and Logic Gates Exercise 4 ◼ Design the circuits for the following Boolean algebraic expressions: (𝑥 + 𝑦) 𝑥 ◼ Solution: x 𝒙+𝒚 𝒙+𝒚 𝒙+𝒚 𝒙 y Lecture 3 – Binary System and Logic Gates The Half-Adder ◼ Sum = 𝑥ҧ ∙ 𝑦 + 𝑥 ∙ 𝑦ത x y Carry Sum = 𝑥 + 𝑦 ∙ (𝑥ҧ + 𝑦) ത 0 0 0 0 = 𝑥 + 𝑦 ∙ (𝑥𝑦) 0 1 0 1 ◼ Carry = 𝑥 ∙ 𝑦 1 0 0 1 1 1 1 0 x y Sum Carry Lecture 3 – Binary System and Logic Gates Examples of Essential Circuits in Digital Logic Design ◼ Performing arithmetic operations ◼ Half-adder and full-adder ◼ Executing logic operations ◼ Compare for equality ◼ Circuits in the control unit ◼ See Slide 7-13 in Lecture 2 ◼ Providing memory capabilities ◼ AND-OR latch Source: The Crash Course Computer Science Lecture 3 – Binary System and Logic Gates Circuit Equivalence (AB + AC) Lecture 3 – Binary System and Logic Gates Circuit Equivalence (AB + AC) Both circuits produce the exact same output for each input value combination, but one is simpler than the other. Lecture 3 – Binary System and Logic Gates Minimization ◼ Boolean algebra allows us to apply provable mathematical principles, like the properties of Boolean algebra listed below, to simplify the design of logic circuits. ◼ In the previous slide, 𝐴 ⋅ 𝐵 + 𝐶 is simpler than (𝐴 ⋅ 𝐵) + (𝐴 ⋅ 𝐶) ◼ 𝐴 ⋅ 𝐵 + 𝐶 uses only two gates. ◼ (𝐴 ⋅ 𝐵) + (𝐴 ⋅ 𝐶) uses three gates. Lecture 3 – Binary System and Logic Gates 10. Summary ◼ Number Systems: Decimal, Binary, Octal, Hexadecimal ◼ Convert Decimal to other number systems and vice versa ◼ Binary arithmetic ◼ Boolean logic and basic Boolean operations ◼ Gates and Boolean logic Lecture 3 – Binary System and Logic Gates