Lecture 3: Binary values and number systems Information Layer Lecture 3: Binary values and number systems
Layers of Computing Systems Communications Applications Operating Systems Programming Hardware Information
Information Information Layer 01001010101010 numbers audio text Images video 01001010101010
Binary values and number systems Numbers and Computing Positional notation Binary, Octal and Hexadecimal Arithmetic in other bases Power of 2 Number Systems Converting from base 10 to other bases Binary values and computers
Numbers and Computing Computer executes numeric computations All types of information that is stored on a computer is stored as numbers (0s and 1s) Number – unit belonging to an abstract mathematical system and is a subject to specified laws of succession, addition and multiplication
Positional notation How many ones are there in 943? The answer depends on base Base of a number system specifies the number of digits used in the system. Digits always begin with 0 and continue through one less than the base Eg. Base 10: has digits from 0 to 9
Base 10 (decimal) Base 2 (binary) Base 8 (octal) Base 16 (hexadecimal) 1 2 10 3 11 4 100 5 101 6 110 7 111 8 1000 9 1001 1010 12 A 1011 13 B 1100 14 C 1101 15 D 1110 16 E 1111 17 F 11000 20
Positional notation The rightmost digit represents its value multiplied by the base to the zeroth power, the digit to the left represents its value multiplied by the base to the first power Number 943 demystified: 9 4 3 9*102 4*101 3*10 0 900 40 943
9*x2+4*x1+3*x0 Formal notation If a number in the base R number system has n digits, it is represented as follows, where di represents the digit in the ith position in the number dn*Rn-1+dn-1*Rn-2+...+d2*R+d1
dn*Rn-1+dn-1*Rn-2+...+d2*R+d1 Decompose number 2458 using the formula above You can also use 9 4 3 9*102 4*101 3*10 0 900 40 943
Why? Why would you need to represent values in base 2? 8? 13? 45???
binary to decimal To convert a number from binary to base 10, just break the number into a sum of numbers from the above list. Example: Convert 100112 to base 10 100112 = 100002 + 102 + 1 = 16 + 2 + 1 = 1910 100002 = 16 + 102 = 2 12 = 1 ---------------- 1910
Decimal to other bases While (the quotient is not zero) Divide the decimal number by the new base Make the remainder the next digit to the left of the answer Replace the decimal number with the quotient
Decimal to other bases Remainder 12 11 1 C B A - ABC
Binary to octal To convert from binary to octal, you start at the rightmost binary digit and mark the digits in groups of threes. Then you convert each group of three to its octal value. E.g. 1010110
Binary to hexadecimal mark digits from right to left in groups of four. 1010110
Arithmetic in other bases Basic addition in decimal (base 10) 0+1=1 1+1=2 2+1=3 9+1=10 Because there is no symbol for 10, we reuse same digits and rely on position. The rightmost digit reverts to 0 and there is a carry into next position to the left
Octal to decimal (1336)8 = (1 x 83) + (3 x 82) + (3 x 81) + (6 x 80) = (1 x 512) + (3 x 64) + (3 x 8) + (6 x 1) = 512 + 192 + 24 + 6 = 734 Thus (1336)8 = (734)10
Octal to binary look up each octal digit to obtain the equivalent group of three binary digits. Octal = 3 4 5 Binary = 011 100 101 = 011100101 binary
Octal to hex When converting from octal to hexadecimal, it is often easier to first convert the octal number into binary and then from binary into hexadecimal. For example, to convert 345 octal into hex: Octal = 3 4 5 Binary = 011 100 101 = 011100101 binary
Octal to hex Drop any leading zeros or pad with leading zeros to get groups of four binary digits (bits): Binary 011100101 = 1110 0101 Then, look up the groups in a table to convert to hexadecimal digits.