Lecture 2 Binary Values and Number Systems Positional Notation 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. 94310 = 9(100) + 4(10) + 3 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. 1101012 = 1(32) + 1(16) + 0(8) + 1(4) + 0(2) + 1 = 5310 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. decimal 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 A single binary digit is called a bit. Eight bits is called a byte, four bits is called a nibble. base 2 10111010001010101111000010101011 we can convert from base 2 to base 8 by evaluating groups of 3 bits at a time 10 111 010 001 010 101 111 000 010 101 011 we an convert from base 2 to base 16 by evaluating groups of 4 bits at a time 1011 1010 0010 1010 1111 0000 1010 1011 2 7 B 2 A 1 2 5 2 A 7 F 0 0 2 5 A 3 B base 8 base 16 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 binary octal 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 0 1 2 3 4 5 6 7 10 11 12 13 14 15 16 17 hexadecimal 0 1 2 3 4 5 6 7 8 9 A B C D E F Converting Between Base 10 and Base 2 Let’s convert 142 to base 2 142/2 = 71 71/2 = 35 35/2 = 17 17/2 = 8 8/2 = 4 4/2 = 2 2/2 = 1 1/2 = 0 remainder 0 remainder 1 remainder 1 remainder 1 remainder 0 remainder 0 remainder 0 remainder 1 Let’s convert 101100101 to base 10 10001110 1 4 32 64 + 256 357 Left to Right Evaluation 1=1 10 = 2x1 = 2 101 = 2x2 + 1 = 5 1011 = 2x5 + 1 = 11 10110 = 2x11 = 22 101100 = 2x22 = 44 1011001 = 2x44 + 1 = 89 10110010 = 2x89 = 178 101100101 = 2x178 + 1 = 357 Base 2 Arithmetic optional Addition 10001010 + 00101110 10111000 Converting a Number to Two’s Complement* 00011101 11100010 + 1 11100011 Subtraction this is the base 2 representation for 29 flip all the bits add 1 this is the two’s complement representation for -29 ignore overflow 01111011 + 11100011 this is 123 this is -29 101011110 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 12... 00001100 + 11100011 11101111 most significant digit a 1 means values is negative *Two’s complement is a special way to represent negative values for base-2 integers. 11101111 00010000 + 1 00010001 magnitude is 17 so 11100011 = -17