Lecture 2 Binary Values and Number Systems
The number 943 is an example of a number written in positional notation. The relative positions of the digits determine the values they represent. In base-10 each successive digit (reading from right to left) is worth ten times the previous position. In modern computers numbers are represented in base-2. This means that 0 and 1 are the only digits permitted and each position in a multi-digit number is worth two time the previous position. Positional Notation = 9(100) + 4(10) = 1(32) + 1(16) + 0(8) + 1(4) + 0(2) + 1 = 53 10
Binary, Octal, and Hexadecimal Numbers Base 2 (binary), base 8 (octal), and base 16 (hexadecimal) are all powers of 2 bases so it is easy to convert between them. Base 2 – digits 0,1 Base 8 – digits 0,1,2,3,4,5,6,7 Base 16 – digits 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F ABCDEF ABCDEF binary octal hexadecimal B A 2 A F 0 A B decimal we can convert from base 2 to base 8 by evaluating groups of 3 bits at a time we an convert from base 2 to base 16 by evaluating groups of 4 bits at a time base 2 base 8 base 16 A single binary digit is called a bit. Eight bits is called a byte, four bits is called a nibble.
Converting Between Base 10 and Base 2 Let’s convert 142 to base 2 142/2 = 71 remainder 0 71/2 = 35 remainder 1 35/2 = 17 remainder 1 17/2 = 8 remainder 1 8/2 = 4 remainder 0 4/2 = 2 remainder 0 2/2 = 1 remainder 0 1/2 = 0 remainder Let’s convert to base 10 1 = 1 10 = 2x1 = = 2x2 + 1 = = 2x5 + 1 = = 2x11 = = 2x22 = = 2x = = 2x89 = = 2x = Left to Right Evaluation
Base 2 Arithmetic optional Addition Converting a Number to Two’s Complement* *Two’s complement is a special way to represent negative values for base-2 integers this is the base 2 representation for 29 flip all the bits add 1 this is the two’s complement representation for Subtraction ignore overflow this is 123 this is -29 this is 94 When the binary value has a leading 1, the number is negative...to find the magnitude of this value we need to take the two’s complement again. Lets add -29 to most significant digit a 1 means values is negative magnitude is 17 so = -17