Download presentation
Presentation is loading. Please wait.
Published byAlban Hart Modified over 9 years ago
1
CS231 Fundamentals1 Fundamentals What kind of data do computers work with? – Deep down inside, it’s all 1s and 0s What can you do with 1s and 0s? – Boolean algebra operations – These operations map directly to hardware circuits
2
CS231 Fundamentals2 Computers are binary devices Computers use voltages to represent information Voltages are usually limited to 2.5-5.0V to minimize power consumption This is only enough to represent two discrete (digital) signals – Low and High – 0 and 1 – False and True Why? – To account for noise – To prevent transitional errors How can we use these two signals to represent numbers? Volts 5 4 3 2 1 0 High Low Volts 5 4 3 2 1 0 High Low Medium Good! Bad!
3
CS231 Fundamentals3 Decimal review Numbers consist of a bunch of digits, each with a weight These weights are all powers of the base, which is 10. We can rewrite this: To find the decimal value of a number, multiply each digit by its weight and sum the products. (1 x 10 2 ) + (6 x 10 1 ) + (2 x 10 0 ) + (3 x 10 -1 ) + (7 x 10 -2 ) + (5 x 10 -3 ) = 162.375
4
CS231 Fundamentals4 Converting binary to decimal We can use the same trick to convert binary, or base 2, numbers to decimal. This time, the weights are powers of 2. – Example: 1101.01 in binary – The decimal value is: (1 x 2 3 ) + (1 x 2 2 ) + (0 x 2 1 ) + (1 x 2 0 ) + (0 x 2 -1 ) + (1 x 2 -2 ) = 8+ 4+ 0+ 1+ 0+ 0.25= 13.25
5
CS231 Fundamentals5 Opposite: converting decimal to binary To convert an integer, keep dividing by 2 until the quotient is 0. Collect the remainders in reverse order. To convert a fraction, keep multiplying the fractional part by 2 until it becomes 0. Collect the integer parts (in forward order). – This may not terminate! Example: 162.375: So, 162.375 10 = 10100010.011 2 162 / 2= 81rem 0 81 / 2= 40rem 1 40 / 2= 20rem 0 20 / 2= 10rem 0 10 / 2= 5rem 0 5 / 2= 2rem 1 2 / 2= 1rem 0 1 / 2= 0rem 1 0.375 x 2 = 0.750 0.750 x 2 = 1.500 0.500 x 2 = 1.000
6
CS231 Fundamentals6 Why does this work? This works for converting from decimal to any base Why? Think about converting 162.375 from decimal to decimal. Each division “strips off” the rightmost digit (the remainder). The quotient represents the remaining digits in the number. Similarly, each multiplication “strips off” the leftmost digit (the integer part). The fraction represents the remaining digits. 162 / 10= 16rem 2 16 / 10= 1rem 6 1 / 10= 0rem 1 0.375 x 10 = 3.750 0.750 x 10 = 7.500 0.500 x 10 = 5.000
7
CS231 Fundamentals7 Base 8 and base 16 are useful too Octal (base 8) digits range from 0 to 7. Since 8 = 2 3, one octal digit is equivalent to 3 binary digits. Hexadecimal (base 16) digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F. Since 16 = 2 4, one hex digit is equivalent to 4 binary digits. We typically use octal and hex as a shorthand for those long messy binary numbers.
8
CS231 Fundamentals8 Binary, octal, hexadecimal Converting from octal (or hex) to binary is easy: just replace each octal (or hex) digit with the equivalent 3 (or 4) bit sequence To convert from binary to octal (or hex): starting from the binary point, make groups of 3 (or 4) bits. Add 0s to the ends of the number if needed. Then, just convert each bit group to its corresponding octal (or hex) digit. 261.35 8 =261.35 8 =010110001.011101 2 261.35 16 =261.35 16 =001001100001.00110101 2 10110100.001011 2 =10110100.00101100 2 =B4.2C 16 10110100.001011 2 =010110100.001011 2 =264.13 8 These binary numbers are not equivalent! These numbers are equivalent!
9
CS231 Fundamentals9 Functions A computer takes input and produces output... just like a math function! We can express math functions in two ways We can represent binary functions in two ways too: – As a Boolean expression – As a truth table. It shows all possibilities for an expression. f(x,y)= 2x + y = x + x + y = 2(x + y/2) =... As an expressionAs a function table
10
CS231 Fundamentals10 Basic Boolean operations There are three basic operations. Each can be implemented in hardware using a primitive logic gate AND (product) of two inputs OR (sum) of two inputs NOT (complement) on one input xyx + yx’ Operation: Expression: Truth table: Logic gate:
11
CS231 Fundamentals11 Boolean expressions We can use these basic operations to form more complex expressions and equations Some terminology and notation – f is the name of the function – (x,y,z) are the input variables. Each variable represents a 1 or 0. Listing input variables is optional; instead we often write – A literal is an occurrence of an input variable or its complement. The function above has four literals: x, y’, z, and x’. – Without parentheses, the NOT operation has the highest precedence, followed by AND, and finally OR. Fully parenthesized, this function is f(x,y,z) = (x + y’)z + x’ f = (x + y’)z + x’ f(x,y,z) = (((x +(y’))z) + x’)
12
CS231 Fundamentals12 Larger circuits We can build circuits for arbitrary expressions, using our basic gates f(x,y,z) = (x + y’)z + x’ y’ (x + y’) x’ (x + y’)z
13
CS231 Fundamentals13 Truth tables We can make a truth table too, by evaluating the function for all possible inputs. In general, a function with n inputs will have 2 n possible inputs. The inputs are typically listed in binary order. f(0,0,0)= (0 + 1)0 + 1= 1 f(0,0,1)= (0 + 1)1 + 1= 1 f(0,1,0)= (0 + 0)0 + 1= 1 f(0,1,1)= (0 + 0)1 + 1= 1 f(1,0,0)= (1 + 1)0 + 0= 0 f(1,0,1)= (1 + 1)1 + 0= 1 f(1,1,0)= (1 + 0)0 + 0= 0 f(1,1,1)= (1 + 0)1 + 0= 1 f(x,y,z) = (x + y’)z + x’
14
CS231 Fundamentals14 Summary – To minimize analog voltage problems, computers are binary devices – That means we have to think in terms of base 2 – The basic operations on binary values include AND, OR, and NOT – These can be directly implemented in hardware (eventually we’ll show how to do useful stuff with these operations) – Expressions and truth tables are used to design and describe circuits We’ve already seen some of the recurring themes of architecture: – We use 0 and 1 as abstractions for analog voltages – Gates are also an abstraction of the underlying technology – We showed how to represent numbers using just these two signals Next time: – Using Boolean algebra to simplify expressions – This in turn will yield a simpler circuit
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.