Download presentation
Presentation is loading. Please wait.
Published byEmma Park Modified over 9 years ago
1
Click to edit Master title style Click to edit Master text styles –Second level Third level –Fourth level »Fifth level 1 Today’s Topics How information is encoded –signed magnitude –1s complement –2s complement Base conversion Arithmetic and logical operations
2
Click to edit Master title style Click to edit Master text styles –Second level Third level –Fourth level »Fifth level 2 Symbolic Representation of Voltage Devices that react to presence/absence of voltage (within a tolerance) are easier to build than devices that react to a specific voltage We use 1 and 0 for presence/absence bit = binary digit 8 bits = 1 byte
3
Click to edit Master title style Click to edit Master text styles –Second level Third level –Fourth level »Fifth level 3 Positional Notation 1 position: 0 or 1 (2 1 ) 2 positions: 00, 01, 10, 11 (2 2 ) 3 positions: 000, 001, 010, 011, 100, 101, 110, 111 (2 3 ) A single wire can represent only one thing, a collection of k them can represent (2 k ) different things
4
Click to edit Master title style Click to edit Master text styles –Second level Third level –Fourth level »Fifth level 4 Data Types A data type is a set of values and operations over those values –ASCII codes for keyboard characters –2s complement integers –others will be illustrated
5
Click to edit Master title style Click to edit Master text styles –Second level Third level –Fourth level »Fifth level 5 Binary or Base-2 Integers Decimal representation 107 = 1x100+0x10+7 d 2 ·10 2 + d 1 ·10 1 + d 0 ·10 0 Binary representation 107 = 01101011 0·2 7 + 1·2 6 + 1·2 5 + 0·2 4 + 1·2 3 + 0·2 2 + 1·2 1 + 1·2 0 a 7 ·2 7 + a 6 ·2 6 + a 5 ·2 5 + a 4 ·2 4 + a 3 ·2 3 + a 2 ·2 2 + a 1 ·2 1 + a 0 ·2 0
6
Click to edit Master title style Click to edit Master text styles –Second level Third level –Fourth level »Fifth level 6 Integer Data Types Unsigned integers: non-negative values from 0 to 2 k -1 for k bits Signed integers: use half of the 2 k values for positive and half for negative –signed magnitude: leading bit represents the sign (0=positive) and remaining bits are the value –1s complement: flip bits for negative value –2s complement: 1s complement + 1
7
Click to edit Master title style Click to edit Master text styles –Second level Third level –Fourth level »Fifth level 7 1s Complement Flip bits to represent negative values: 4 is 0100 -4 is 1011 Basic logic circuits for signed magnitude and 1s complement are more complex than 2s complement
8
Click to edit Master title style Click to edit Master text styles –Second level Third level –Fourth level »Fifth level 8 Motivation for 2s Complement From a device standpoint, it would be nice if adding x to -x yields the representation for 0 … then we can build circuits that don’t care if the operands are positive or negative Binary addition: 00011 00110 01001
9
Click to edit Master title style Click to edit Master text styles –Second level Third level –Fourth level »Fifth level 9 Computing 2s Complement Use binary value for positive integers Compute representation for negative integers: –take 1s complement –add 1 Example: what is 9 in binary? –what is its 1s complement value? –what is 1 + 1s complement value? –What do you get when you sum 9 and -9 in binary?
10
Click to edit Master title style Click to edit Master text styles –Second level Third level –Fourth level »Fifth level 10 Binary to Decimal Conversion Represent values from -2 k-1 to 2 k-1 -1 with k bits Algorithm: –if the leading bit is 1, apply 2s complement to obtain the magnitude of the negative number –sum the powers of 2 with coefficients of 1
11
Click to edit Master title style Click to edit Master text styles –Second level Third level –Fourth level »Fifth level 11 Decimal to Binary Conversion For positive numbers, do the computation below and prefix with a leading 0 For negative numbers, use the absolute value in the computation below, add a leading 0, and take the 2s complement Algorithm: –divide 2 into the dividend, write the remainder on the right –the quotient becomes the new dividend; repeat until the quotient is 0 –read the binary number from the bottom up
12
Click to edit Master title style Click to edit Master text styles –Second level Third level –Fourth level »Fifth level 12 Decimal to Binary Conversion Example Lets convert –124 to 8-bit 2’s complement binary representation 1)|-124| = 124 2)Compute binary representation of 124 3)Add leading 0 and compute 2’s complement 124 2=62 remainder 0 62 2=31 remainder 0 31 2=15 remainder 1 15 2=7 remainder 1 7 2=3 remainder 1 3 2=1 remainder 1 1 2=0 remainder 1 1111100 2)3) 01111100 10000011 10000100
13
Click to edit Master title style Click to edit Master text styles –Second level Third level –Fourth level »Fifth level 13 Operations on Bits: Arithmetic We can do addition already … so we can do subtraction, too a - b = a + -b Compute the 2s complement of b, add it to a
14
Click to edit Master title style Click to edit Master text styles –Second level Third level –Fourth level »Fifth level 14 Sign Extension To add two numbers of different sizes, it is necessary to make them the same length For positive numbers, pad with leading 0s For negative numbers, pad with leading 1s Does not change the values!
15
Click to edit Master title style Click to edit Master text styles –Second level Third level –Fourth level »Fifth level 15 Overflow Happens when the sum of two positive numbers is larger than the largest possible positive number Or alternately, the sum of two negative numbers is smaller than the smallest possible negative number We check to see if we get a negative value when adding two positive numbers, or vice versa Why is there never an overflow with the sum of a positive and negative value?
16
Click to edit Master title style Click to edit Master text styles –Second level Third level –Fourth level »Fifth level 16 Operations on Bits: Logical Ops Basic logic functions: AND, OR, NOT, XOR Result from treatment of 0 as FALSE and 1 as TRUE Truth tables: consider all possible combinations of input values and shows output values in last column For n inputs, there are n+1 columns and 2 n rows
17
Click to edit Master title style Click to edit Master text styles –Second level Third level –Fourth level »Fifth level 17 Truth table for the AND operator aba AND b 000 010 100 111
18
Click to edit Master title style Click to edit Master text styles –Second level Third level –Fourth level »Fifth level 18 Logical Operations AND: true when both inputs are 1, else false OR: true when either input is 1, else false XOR: false if both inputs are the same, else true NOT: invert/complement input All ops can be applied to an entire bitstring (NOT) or pair of bitstrings (AND, OR, XOR) by corresponding positions
19
Click to edit Master title style Click to edit Master text styles –Second level Third level –Fourth level »Fifth level 19 Logic Functions Used for comparisons, e.g., if two integers are identical, the output of XOR is all 0s Basis for implementing all of the computer’s functionality!
20
Click to edit Master title style Click to edit Master text styles –Second level Third level –Fourth level »Fifth level 20 Other Representations Floating point: real numbers using normalized scientific notation ASCII: 256 possible symbols (keyboard input) Hexadecimal: base 16 –each group of 4 bits is a hex digit –convenience for humans
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.