# binary numbers

Post on 25-May-2015

454 views

Category:

## Education

Tags:

• #### following binary number

Embed Size (px)

DESCRIPTION

Information technology

TRANSCRIPT

• 1. Recall . . . The definition of a computer Analog/Digital Electric/Mechanical General Purpose/Special Purpose The General Purpose Electronic Computer General Purpose Binary Binary?2-1

2. 2-2 3. Binary Circuitry Binary circuitry: cheap reliable able to be extended to very complicated logic built on only two states ON (1) OFF (0) 2-3 4. Computers work in Binary Computers are not only powered by electricity they compute with electricity they shift voltage pulses around internally circuits allow for electricity to flow or to be blocked depending on thetype of circuitClosed OpencircuitcircuitON or 1 OFF or 0 2-4 5. Representation of Data So, our binary computer can represent: 0s and 1s. . . We need to represent considerably more than that: Numbers Characters Visual Data Audio Data Instructions and we need to do it with only 0s and 1s2-5 6. Representation of Numbers Representing numbers is considerably more thansomething that looks like the symbol 1 or 2 or 430 Were trying to represent numbers; which have conceptual meaning9 = 3+3+3 = 4+5 = 10-1 = 3*3 = 3^3 = 9 2-6 7. Representation of Numbers Decimal numeration system: (aka base 10) Uses 10 symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. The place values of each position are increasing powers of ten. A number such as 1428 literally means: Eight Ones Two Tens 104 103 102101 100 Four Hundreds One (A single) Thousand 10000 1000 100101= (1 x 1000) + (4 x 100) + (2 x 10) + (8 x 1)2-7 8. Combinations Imagine we have three light-bulbs in a row, and each bulbcan be on (1) or off (0). How many unique combinations of lights can we have? (Hint, start with all lights off)2-8 9. Combinations The number of unique combinations we can have of one light with twostates per lights is two: 0 1 The number of unique combinations we can have of two lights with twostates per light is four:00 01 10 11 The number of unique combinations we can have of three lights with twostates per lights is eight:000 100 001 101 010 110 011 111 2-9 10. Representation of Numbers Our three-light system has eight possible combinations of on and off. With eight uniquecombinations, we couldrepresent the numbers 0, 1, 2, 3, 4, 5, 6, 7 0 = 0004 = 100 1 = 0015 = 101 2 = 0106 = 110 3 = 0117 = 1112-10 11. Representation of Numbers Binary numeration system (aka base 2): Will use 2 symbols: 0, and 1.(Each is called a bit for binary digit) The place values of each position are powers of two. A binary number such as 10110two will be expanded as: Zero Ones One Two24 232221 20 One Four168 42 1 Zero Eights One Sixteen 10 11 0 = (1 x 16) + (0 x 8) + (1 x 4) + (1 x 2) + (0 x 1) = 22 in decimal2-11 12. Binary-to-Decimal Conversion Convert the following binary number (base two) in decimal(base ten) 1 0 0 0 0 0 1 12-12 13. Binary Conversion1 0 0 0 0 0 1 1 Step 1: Make a table with the same number of columns as places in the binary string and copy the string into the table 1000 00112-13 14. Binary Conversion Step 2: Write out the powers of two corresponding to eachposition in the binary number:27 2625 24 2322 2120 100 000 11 2-14 15. Binary Conversion Step 3: Write out the powers of two corresponding to eachposition in the binary number in decimal: 5 27 26 224 23 22 21 20128 64 32 16 842110 0 0001 12-15 16. Binary Conversion Step 4: multiply the second and third rows and put the result inthe fourth row: 27 26 2524 232221 20128 64 3216 8 4 211 0 0 0 0 01 1128 0 0 0 0 02 12-16 17. Binary Conversion Step 5: (final step) Add up all the numbers in the fourth row27 262524 23222120 128 64 32168 4 2 11 00 0 0 0 11 12800 0 0 0 21 128+0+0+0+0+0+2+1 = 1312-17 18. 2-18 19. Decimal to Binary2(number of places) = number of unique combinations we can achieve with some number of places in binary; but we have to use one of the mappings for zero so. . .2(number of places) - 1 = largest binary number we can store with that many places1 21 1 = 1 with 1 place we can store numbers from 0 to 15 25 1 = 31 with 5 places we can store numbers from 0 to 317 27 1 = 127 with 7 places we can store numbers from 0 to 1278 28 1 = 255 with 8 places we can store numbers between 0 and 2552-19 20. Binary ConversionStep 2: Write out a binary conversion table with n many places, and fill in the values of the first two rows:27 262524232221 20 128 64 3216 8 4 212-20 21. Binary Conversion Step 3: Subtract out the decimal powers of two from leftto right. If you can subtract that amount and the result is non-negative, write a 1 in the binary string and continue with the result If the subtraction results in a negative number, write a 0 and continue with the last positive number272625 2423 22 2120 128 64 32 16 84 21245245- 117 -53 - 21 -5 - 8 5 - 4 1 - 2 1 - 1128 = 64 =32 = 16 = = -3= 1 = -1= 0 117 5321 5error error 111 101 01 2-21 22. Addition/Subtraction Addition in any number system. . . We add in the places from right to left If the sum of the two numbers exceeds the symbols we have at our disposal we carry some amount. . .4 + 8 = twelve ; in base ten, we have no single numeric symbolthat equals twelve We dont need to express twelve in a single symbol, because wecan do so by breaking the number down and incrementing the base Instead we write 12 which is: One Ten and Two Ones. Logically, we subtract 10 (the base amount) from our sum, andwrite the result in that place, and we carry a one into the nextplace, which represents One additional ten (our base number) 2-22 23. Binary Addition Addition of binary numbers: 0 + 0 = 0 0 + 1 = 1 1 + 0 = 1 1 + 1 = 2ten How do we write this?So well carry the symbol 1 into the next place (which represents two in decimal), and well write down the sum minus our base amount (2)1 + 1 = 10twoExample: adding two binary numbers 2-23 24. Binary Subtraction Subtraction of binary numbers:0 - 0 = 00 - 1 = -1 problem! We need to borrow 1 - 0 = 11 - 1 = 0Remember when borrowing in base 10: We decrease the symbol to the left by one Remember when we borrow 1 from the symbol to our left, it has a value thats ten more (or the base amount) 2-24 25. Binary Subtraction Lets subtract the following numbers: 1 0 0 0 0 0 1 1 - 0 1 0 0 0 1 0 0------------------2-25 26. Binary Subtraction We need to borrow for the third term, but the eighth is the closestterm with something to borrow from! 1 0 0 0 0 0 1 1 - 0 1 0 0 0 1 0 0------------------ 1 1 2-26 27. Binary Subtraction So, we borrow 2ten from the first place we can 0 2 1 0 0 0 0 0 1 1 - 0 1 0 0 0 1 0 0------------------ 2-27 28. Binary Subtraction Keep borrowing two 1 0 2 2 1 0 0 0 0 0 1 1 - 0 1 0 0 0 1 0 0------------------1 12-28 29. Binary Subtraction Keep borrowing 2 . . . 1 1 0 2 2 2 1 0 0 0 0 0 1 1 - 0 1 0 0 0 1 0 0------------------ 1 12-29 30. Binary Subtraction Keep borrowing 2 . . . 1 1 1 0 2 2 2 2 1 0 0 0 0 0 1 1 - 0 1 0 0 0 1 0 0------------------ 1 12-30 31. Binary Subtraction 1 1 1 1 0 2 2 2 2 2 now, were able to subtract here 1 0 0 0 0 0 1 1 - 0 1 0 0 0 1 0 0------------------ 1 1 12-31 32. Binary Subtraction The rest of the subtractions are easy . . .1 1 1 1 0 2 2 2 2 2 1 0 0 0 0 0 1 1 - 0 1 0 0 0 1 0 0------------------ 0 0 1 1 1 1 1 1So our answer is -> 00111111Lets convert to decimal to check our work2-32 33. Binary Subtraction converting binary to decimal we get. . . 1 0 0 0 0 0 1 1 -> 128+2+1 = 131 - 0 1 0 0 0 1 0 0 -> 64+4 = 68------------------ 0 0 1 1 1 1 1 1 -> 32+16+8+4+2+1 = 67 131 68 = 67 2-33 34. Binary Numbers Binary numbers actually have some other neat propertiesas well . . . QUESTION: Can you multiply a binary number by two (decimal) and give the result in binary quickly? Multiply the number 00110 by two (and give the answer in binary) Why does this work? 2524 2322 21 2032168 421 0 00 1102-34