CSE 111 Representing Numeric Data in a Computer Slides adapted from Dr. Kris Schindler
Unsigned Binary Numbers Range: 0 2 n -1 where n is the number of bits Positional Notation Example: two
Unsigned Binary Numbers How do we convert from a decimal number to a binary number? Continue until q=0
Unsigned Binary Numbers How do we convert from a decimal number to a binary number? Example: 39 ten
Bit Positions MSB Most Significant Bit Leftmost Bit Position LSB Least Significant Bit Rightmost Bit Position
Signed Binary Numbers The most significant bit (leftmost) represents the sign Negative (-): 1 Positive (+): 0
Signed Binary Numbers Computers represent signed numbers using two’s complement notation
Signed Binary Numbers Two’s Complement Representation of a negative binary number Consider an n-bit number, x The two’s complement of the number is 2 n - x This process is called taking the two’s complement of a number Taking the two’s complement of a number negates it
Signed Binary Numbers Two’s Complement Shortcut for taking the two’s complement of a number Start at the least significant (rightmost) bit and move left (toward the most significant bit) Keep every bit until you reach the first 1 Keep that 1 Invert every bit (0 1,1 0) after the first 1 as you continue to move left
Signed Binary Numbers Two’s Complement Examples: -4 Take the two’s complement of 4 ( ) = -4 -9 Take the two’s complement of 9 ( ) = -9 Since the above are negative, taking the two’s complement will allow you to determine the magnitude, which is the positive equivalent
Signed Binary Numbers Two’s Complement Examples: +6 Since the number is positive, you don’t need to take the two’s complement = +6 +18 Since the number is positive, you don’t need to take the two’s complement = +18
Signed Binary Numbers Two’s Complement Since taking the two’s complement of a number negates it, taking the two’s complement twice gives you the original number back Example: +12 is represented by Taking the two’s complement results in -12 ( ) Taking the two's complement of -12 results in +12 ( )
Floating Point Very large/small numbers Fractions Example 8.5 x 2 23 x 2 23 Normalized x 2 27 Exponent Bias = = 153 = Significand: Sign: 0 Number:
References J. Glenn Brookshear, Computer Science - An Overview, 11 th edition, Addison-Wesley as an imprint of Pearson, 2012 Donald D. Givone, Digital Principles and Design, McGraw-Hill, 2003 John L. Hennessy and David A. Patterson, Computer Organization and Design, The Hardware/Software Interface, 3 rd Edition, Morgan Kaufmann Publishers, Inc., 2005