CMSC250 Fall 2018 Circuits 1 1
Logic == Math? What calculations can we do with logic? Add, subtract, multiply? George Boole – 1800’s. Boolean logic Claude Shannon – 1937. Logic == circuits == math T = 1 p v q == p+q p v ~q F = 0 p ^ q == p*q is ~ p == (1-q) p + (1-q)
Find Boolean formula for: p, q & r are the variables. p q r output 1 3 For each output row which has a 1, form a statement which is true only for the values of the inputs in that row. For this example, it would be rows 1, 2, and 4, and the statements would be (p q r) (p q r) (p q r) Then OR them all together. For this example the result would be (p q r) (p q r) (p q r) This procedure always works.
Find Boolean Formula For each row with output 1 obtain “mini-formula” which is 1 exactly on that row. OR together all of the mini-formulas 111, 110, and 100 all output 1 p^q^r, p^q^~r, p^~q^~r (p^q^r)(p^q^~r)(p^~q^~r) 4
Basic logic gates AND gate: OR gate: NOT gate: 5 We can recast everything we’ve done so far in terms of circuits. These circuits are what are actually inside a computer and allow it to work. AND, OR, and NOT gates really exist! 5
Basic logic gates AND gate: OR gate: NOT gate: 6 We can recast everything we’ve done so far in terms of circuits. These circuits are what are actually inside a computer and allow it to work. AND, OR, and NOT gates really exist! 6
Circuit to Boolean formula Given this circuit, convert to logic
Circuit to Boolean formula Given this circuit, convert to logic p v ~(p ^ r)
Draw a circuit for: p, q & r are inputs. Simplify before building the circuit. p q r output 1 For each output row which has a 1, form a statement which is true only for the values of the inputs in that row. For this example, it would be rows 1, 2, and 4, and the statements would be (p q r) (p q r) (p q r) Then OR them all together. For this example the result would be (p q r) (p q r) (p q r) This procedure always works. 9
Number conversions Different number system bases are used when convenient some commonly-used bases are 10 (decimal), 2 (binary), 8 (octal), 16 (hexadecimal) the base tells how many different numerals are used the base also determines the value of each place Conversions from anything to base 10 use the definition of the number system Conversions from base 10 to anything use repeated integer division Circuits can calculate or solve arithmetic functions with base 2 numbers. So we take a detour to base 2. On the board: In base 10: 268 = 2 * 10^2 + 6 * 10^1 + 8 * 10^0. This ONLY uses the digits 0 through 9 A number in base 2 only uses the digits 0 and 1. In base 2: some number like 101101 = 1 * 2^5 + 0 * 2^4 + 1 * 2^3 + 2 * 2^2 + 1 * 2^0 10
Addition of binary numbers Carry if the number would be too large for the number system- if it is greater than 1 1001 + 10 1001 + 11 1011 + 10 1101 + 111 1011 1100 1101 10100 11
Addition of octal and hexadecimal numbers Carry if the number would be too large for the number system (larger than 7 or 15) 7238 + 128 2658 + 338 ABC16 + 1216 CDE16 + ED16 7358 3208 ACE16 DCB16 Explain: Octal is base 8, therefore the octal digits are 0 through 7. Any value which is larger than 7 must result in a carry to the next digit position to the left. Hexadecimal is base 16, so ten digit symbols 0-9 aren’t enough to represent all the hexadecimal digits. So we use letters A, B, C, D, E, and F to represent the hexadecimal digits with values 10, 11, 12, 13, 14, and 15. Hexadecimal is commonly used in computer science, since expressing numbers in binary is tedious. However, computer memory is often organized in terms of bytes, which are 8 bits. Therefore two hexadecimal digits can be used to indicate the first four bits and the second four bits of any byte, more conveniently than 8 bits. For example, the binary number 01101101 is 6D in hexadecimal. Similarly, it's 155 in octal. Octal is less common but sometimes used as well. 12
Two's complement To represent negative values in binary: Find the binary equivalent of the absolute value. Pad on the left to completely fill the bits in the specified bit width Switch all of the 1's to 0's and 0's to 1's. Add 1 to the result. Example: find the 8-bit two's complement representation of -43: 4310 = 1010112 001010112 110101002 110101012 = -4310 13
Using a circuit for adding two bits input output p q carry sum 1 Write as a logic expression Translate to circuits The key is that we’ve translated arithmetic in base 2 to truth tables, now we can do circuits! Note order of rows; this is not a truth table. 14
Half adder Sum = (x v y) ^ ~ (x ^ y) Carry = (x ^ y)
Full adder Three bits in (x, y, previous carry)
Parallel adders Chain these half adders and full adders together for multi-bit addition A3A2A1A0 + B3B2B1B0 = S3S2S1S0 X3 Y3 X2 Y2 This performs addition of 2 3-bit numbers! X1 Y1
Topic not covered Simplifying circuits: there are techniques that exist (which are complex). 18