The Binary Number System
Why is Binary important? Everything on a computer (or other digital device) is represented by Binary Numbers
One to Five in various systems 1 2 3 4 5 I II III IV V 1 10 11 100 101
Decimal System Deci means Ten Base Ten System Ten symbols: 0 1 2 3 4 5 6 7 8 9
Decimal System Example: a decimal number 2 3 0 3 8
Decimal System Digits occupy Places 2 3 0 3 8
Decimal System The places have names 2 3 0 3 8 Ten- Thousand s Thousand s Hundred s Ten s One s
Decimal System Place names as numbers 2 3 0 3 8 10,000 1,000 100 10 1 (See a pattern in the place names?)
Decimal System Place determines the meaning of a digit 2 3 0 3 8 10,000 1,000 100 10 1 3 means three thousand 3 means three tens
Decimal System Place names as exponents of 10 2 3 0 3 8 10 4 10 3 10 2 10 1 10 0 (See a pattern in the place names?)
Bi means Two Base Two System Two symbols: 0 1 Understanding the Decimal system, replace Ten with Two
Place names as exponents of 2 2 4 2 3 2 2 2 1 2 0
Place names expressed in decimal numbers 16 8 4 2 1
Place names expressed in English Sixteen s Eight s Four s Two s One s
Interpreting the bits 1 0 0 1 0 16 8 4 2 1 Where there is a 1: add the place name Where there is a 0: DON T add
Interpreting the bits 1 0 0 1 0 16 8 4 2 1 16 + 2 = EIGHTEEN (18 in decimal)!
Conversion Shortcut: know the pattern! 1.Start with 1 as the right-most digit 2.Multiply by 2 each time, right to left: 1 2 1 4 2 1 8 4 2 1 16 8 4 2 2 32 16 8 4 2 1 64 32 16 8 4 2 1 128 64 32 16 8 4 2 1
Converting Binary to Decimal Example: Convert 10011101 to Decimal: Write the pattern beneath each digit: 1 0 0 1 1 1 0 1 128 64 32 16 8 4 2 1 Add the pattern number where there is a 1: 128 + 16 + 8 + 4 + 1 = 157
Converting Decimal to Binary: Official Method Repeatedly divide by 2 recording the remainders (1 or 0) until the Dividend is 0. The answer is the list of remainders, last to first.
Converting Decimal to Binary: Official Method Example: convert 87 to Binary Dividend Answer: 1 0 1 0 1 1 1 Quotient Remainder 87 43 1 <-- right-most 43 21 1 21 10 1 10 5 0 5 2 1 2 1 0 1 0 1 <-- left-most
Converting Decimal to Binary: Official Method
Converting Decimal to Binary: Other Method 1. Let LeftOver = the number to convert 2. Write the pattern, right to left, until the place number is greater than LeftOver. Discard that digit. 3. Repeat left to right, for each bit: - If LeftOver >= place number: o Write 1 in the bit o Subtract the place number from LeftOver - If LeftOver < place number: o Write 0 in the bit
Converting Decimal to Binary: Other Method Example: Convert 87 to Binary Step 1: Let LeftOver = 87 Step 2: we don t need bit 128 (because 87 < 128), so start with bit 64 XX 64 32 16 8 4 2 1
Converting Decimal to Binary: Other Method Is 87 >= 64? Yes 1 64 32 16 8 4 2 1 LeftOver = 87 64 = 23 Is 23 >= 32? No 1 0 64 32 16 8 4 2 1 LeftOver left at 23
Is 23 >= 16? Yes 1 0 1 64 32 16 8 4 2 1 LeftOver = 23 16 = 7 Is 7 >= 8? No 1 0 1 0 64 32 16 8 4 2 1 LeftOver left at 7 Is 7 >= 4? Yes 1 0 1 0 1 64 32 16 8 4 2 1 LeftOver = 7 4 = 3
Is 3 >= 2? Yes 1 0 1 0 1 1 64 32 16 8 4 2 1 LeftOver = 3 2 = 1 Is 1 >= 1? Yes 1 0 1 0 1 1 1 64 32 16 8 4 2 1 LeftOver = 1 1 = 0 Answer: 1010111
Converting Decimal to Binary: Padding Sometimes a problem may state give the answer in a certain number of bits usually 4,8,16, etc. bits. If your answer contains less than the required number, simply add zeros on the left. Just as, in decimal, 48 = 0048, in Binary 1101 = 00001101
Addition: Adding 2 binary numbers Once again, it works similar to decimal - Starting on the right, going right to left: - Add the two digits (plus the carry if there is one) - Write the one digit result, or - If there is a two digit result, write down the right digit and carry the 1.
Addition: Adding 2 binary numbers Decimal Example: 192 + 889 1 1 1 1 1 1 9 2 1 9 2 1 9 2 + 8 8 9_ + 8 8 9_ + 8 8 9_ 1 8 1 1 0 8 1
Addition: Adding 2 binary numbers Adding in binary is even easier, since for any column, the highest sum is three (carry bits in red): 1 0 0 1 1 + _0 + _1 +_1 +_ 1 0 1 1 0 1 1
Addition: Adding 2 binary numbers Example: 1100 + 1110 (12 + 14 = 26) 1 1 0 0 + 1_1 1 0_ 0 1 1 0 0 + 1_1 1 0_ 1 0 1 1 1 0 0 + 1 _1 1 0_ 0 1 0 1 1 1 0 0 + 1 _1 1 0_ 1 1 0 1 0
Fractions Fractions in binary work as expected, following the pattern of how the Decimal system works the exponent on the base number is subtracted by 1 for each digit to the right. 0 0 4. 8 7 5 10 2 10 1 10 0. 10-1 10-2 10-3 100 10 1. _1_ 10 _1_ 100 _1_ 1000 100 10 1..1.01.001
Fractions 1 0 0. 1 1 1 2 2 2 1 2 0. 2-1 2-2 2-3 4 2 1. _1_ 2 _1_ 4 _1_ 8 4 2 1. 0.5 0.25 0.125 Convert 100.111: 4 + 0.5 + 0.25 + 0.125 = 4.875 Note: the point is called a radix point rather than a decimal point
Summary - for the test: - Know how to convert Binary to Decimal maximum 8 bit integer maximum 2 bits past the radix point - Know how to convert Decimal to Binary integers 0 to 255 fractions of.00,.25,.50, and.75 only - Know how to add two Binary integers - Vocabulary: Radix Point