1 / 23

CS1800 Fall 2013

CS1800 Fall 2013. Binary Numbers. Decimal Integers.  What does a decimal number like "87294" really mean?.  More generally. Notation/Vocabulary. Decimal numbers are written base 10 If we have to distinguish the base, we write in as a subscript, e.g. 87294 10

shamus
Download Presentation

CS1800 Fall 2013

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS1800 Fall 2013 Binary Numbers

  2. Decimal Integers  What does a decimal number like "87294" really mean?  More generally

  3. Notation/Vocabulary • Decimal numbers are written base 10 • If we have to distinguish the base, we write in as a subscript, e.g. 8729410 • 8729410 is read as “87294 base 10” •  We used summation notation on the last slide and we use it in the text.

  4. Integers base b • If n is a non-negative integer and bis an integer b>= 2, n can be expressed uniquelybase b. • The “digits” must be greater than or equal to 0and less than or equal to b-1 • This is a polynomial in bwith coefficientsdk

  5. Base b to Base 10 • 1102 = • 1108 = • 11016 = • 1103 = • 1105 = • 11060 =

  6. Binary Integers • 101102 = 124+023+122+12+0 = 16 + 4 + 2 = 2210 • We can only use 0 and 1. • These are called bits. • Learn the first ten powers of 2. • 1 2 4 8 16 32 64 128 256 512 1024 • 210 = 1024 = 1K ~1000 = 103 • 220 = 1,048,576 = ~1000000 = 106

  7. Counting on your Fingers • http://en.wikipedia.org/wiki/Finger_binary • How high can you count?

  8. Bytes A byte is eight bits A nibble is four bits

  9. Some Arithmetic • In base 10, multiplying and dividing by 10 is easy • x10 just add a 0 on the right 87294x10 = 872940 • /10 just drop the 0 on the right 872940/10 = 87294 • The same works base 2 • 101101 times 2 = 1011010 • 1011010 divided by 2 = 101101 • What about x4, x8, x16?

  10. Decimal to Binary ConversionMost Significant Bit to Least Significant Bit • 100510 = • Remember the powers of 2 • Find the largest power of 2 less than 100510 • 100510 = 51210 + 49310 = 29 + 49310 = 10000000002 + 49310 • Now we need to find the the binary representation of 49310 100510 = 51210 + 49310 = 51210 + 25610 + 23710 = 51210 + 25610 + 12810 + 10910 = 51210 + 25610 + 12810 + 6410 + 4510 = 51210 + 25610 + 12810 + 6410 + 3210 + 1310 = 51210 + 25610 + 12810 + 6410 + 3210 + 810 + 410 + 110 = 11111011012 • Use 0s as place-keepers for the missing powers of 2

  11. Try a few • Convert these to Binary • 2910 = • 7310 = • 6310 = • 25810 =

  12. Try a few - Answers • Convert these to Binary • 2910 = 1610 + 810 + 410 + 110 = 124 + 123 + 122 + 021 + 120 = 111012 • 7310 = 6410 + 810 + 110 = 126 + 025 + 024 + 123 + 022 + 021 + 120 = 10010012 • 6310 = 6410 - 110 = 10000002 - 12 = 1111112 • 25810 = 25610 + 210 = 1000000002 + 102 = 1000000102

  13. How does the card trick work? 2910 = 0111012

  14. Binary to Decimalnumbers without subscripts are base 10 • By adding powers 101012 = 16 + 4 + 1 • By multiply and add 101012 = 101002 + 1 = (10102)2 + 1 = ((1012)2 + 0)2 + 1 = (((102)2 + 1)2 + 0)2 + 1 = (((12 + 0)2 + 1)2 + 0)2 + 1 ----------------------------------------------------- now evaluate = ((( 2 )2 + 1)2 + 0)2 + 1 = (( 5 )2 + 0)2 + 1 = ( 10 )2 + 1 = 21

  15. Simply, start on the left • 101012 • (12 + 0) • (12 + 0)2 + 1 • ((12 + 0)2 + 1)2 + 0 • (((12 + 0)2 + 1)2 + 0)2 + 1

  16. Try a few • 11012 = • 1101112 = • 101101012 = • 1110010110101002 =

  17. Try a few - solutions • 11012 = ((12 + 1)2 + 0)2 + 1 = ((3)2 + 0)2 + 1 = (6)2 + 1 = 13 • 1101112 = ((((12 + 1)2 + 0)2 + 1)2 + 1)2 + 1 = ((((3)2 + 0)2 + 1)2 + 1)2 + 1 = (((6)2 + 1)2 + 1)2 + 1 = ((13)2 + 1)2 + 1 = (27)2 + 1 = 55

  18. Try a few - solutions • 101101012 = = ((((((12 + 0)2 + 1)2 + 1)2 + 0)2 + 1)2 + 0)2 + 1 = ((((((2)2 + 1)2 + 1)2 + 0)2 + 1)2 + 0)2 + 1 = (((((5)2 + 1)2 + 0)2 + 1)2 + 0)2 + 1 = ((((11)2 + 0)2 + 1)2 + 0)2 + 1 = (((22)2 + 1)2 + 0)2 + 1 = ((45)2 + 0)2 + 1 = (90)2 + 1 = 181 • 1110010110101002 =

  19. Decimal to Binary ConversionLeast Significant Bit to Most Significant Bit • 100510 is odd so its binary representation ends in 1

  20. Try a few • 1310 = • 10110 = • 22010 = • 99910 =

  21. Try a few - solutions • 1310 = • 10710 =

  22. Try a few - solutions • 99910 =

  23. Addition in Binary

More Related