Download presentation
Presentation is loading. Please wait.
Published byThomasina Palmer Modified over 9 years ago
1
CS1800 Summer 2014 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 it in as a subscript, e.g. 87294 10 87294 10 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 b is an integer b >= 2, n can be expressed uniquely base b. The “digits” must be greater than or equal to 0 and less than or equal to b-1 This is a polynomial in b with coefficients d k
5
Base b to Base 10 110 2 = 110 8 = 110 16 = 110 3 = 110 5 = 110 60 =
6
Binary Integers 10110 2 = 1 2 4 +0 2 3 +1 2 2 +1 2+0 = 16 + 4 + 2 = 22 10 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 2 10 = 1024 = 1K ~1000 = 10 3 2 20 = 1,048,576 = ~1000000 = 10 6
7
Counting on your Fingers http://en.wikipedia.org/wiki/Finger_binary How high can you count?
8
Bytes kilobytekilobyte (kB)10 3 2 10 megabytemegabyte (MB)10 6 2 20 gigabytegigabyte (GB)10 9 2 30 terabyteterabyte (TB) 10 12 2 40 A byte is eight bits A nibble is four bits
9
Some Arithmetic In base 10, multiplying and dividing by 10 is easy x10just add a 0 on the right 87294x10 = 872940 /10just 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 Conversion Most Significant Bit to Least Significant Bit 1005 10 = Remember the powers of 2 Find the largest power of 2 less than 1005 10 1005 10 = 512 10 + 493 10 = 2 9 + 493 10 = 1000000000 2 + 493 10 Now we need to find the the binary representation of 493 10 1005 10 = 512 10 + 493 10 = 512 10 + 256 10 + 237 10 = 512 10 + 256 10 + 128 10 + 109 10 = 512 10 + 256 10 + 128 10 + 64 10 + 45 10 = 512 10 + 256 10 + 128 10 + 64 10 + 32 10 + 13 10 = 512 10 + 256 10 + 128 10 + 64 10 + 32 10 + 8 10 + 4 10 + 1 10 = 1111101101 2 Use 0s as place-keepers for the missing powers of 2
11
Try a few Convert these to Binary 29 10 = 73 10 = 63 10 = 258 10 =
12
Try a few - Answers Convert these to Binary 29 10 = 16 10 + 8 10 + 4 10 + 1 10 = 1 2 4 + 1 2 3 + 1 2 2 + 0 2 1 + 1 2 0 = 11101 2 73 10 = 64 10 + 8 10 + 1 10 = 1 2 6 + 0 2 5 + 0 2 4 + 1 2 3 + 0 2 2 + 0 2 1 + 1 2 0 = 1001001 2 63 10 = 64 10 - 1 10 = 1000000 2 - 1 2 = 111111 2 258 10 = 256 10 + 2 10 = 100000000 2 + 10 2 = 100000010 2
13
How does the card trick work? 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 2 3 6 7 10 11 14 15 18 19 22 23 26 27 30 31 34 35 38 39 42 43 46 47 50 51 54 55 58 59 62 63 4 5 6 7 12 13 14 15 20 21 22 23 28 29 30 31 36 37 38 39 44 45 46 47 52 53 54 55 60 61 62 63 8 9 10 11 12 13 14 15 24 25 26 27 28 29 30 31 40 41 42 43 44 45 46 47 56 57 58 59 60 61 62 63 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 29 10 = 011101 2
14
Binary to Decimal numbers without subscripts are base 10 By adding powers 10101 2 = 16 + 4 + 1 By multiply and add 10101 2 = 10100 2 + 1 = (1010 2 ) 2 + 1 = ((101 2 ) 2 + 0) 2 + 1 = (((10 2 ) 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 10101 2 (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 1101 2 = 110111 2 = 10110101 2 = 111001011010100 2 =
17
Try a few - solutions 1101 2 = ((1 2 + 1) 2 + 0) 2 + 1 = ((3) 2 + 0) 2 + 1 = (6) 2 + 1 = 13 110111 2 = ((((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 10110101 2 = = ((((((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 111001011010100 2 =
19
Decimal to Binary Conversion Least Significant Bit to Most Significant Bit 1005 10 is odd so its binary representation ends in 1 1005odd subtract 1 and divide by 21 502even subtract 0 and divide by 201 251odd subtract 1 and divide by 2101 125odd subtract 1 and divide by 21101 62even subtract 0 and divide by 201101 31odd subtract 1 and divide by 2101101 15odd subtract 1 and divide by 21101101 7odd subtract 1 and divide by 211101101 3odd subtract 1 and divide by 2111101101 1odd subtract 1 and divide by 21111101101
20
Try a few 13 10 = 101 10 = 220 10 = 999 10 =
21
Try a few - solutions 13 10 = 107 10 = 13 odd1 12/2 = 6 even01 6/2 = 3 odd101 2/2 = 1 odd1101 101 odd1 100/2 = 50 even01 50/2 = 25 odd101 24/2 = 12 even0101 12/2 = 6 even00101 6/2 = 3 odd100101 2/2 = 1 odd1100101
22
Try a few - solutions 999 10 = 999 odd1 998/2 = 499 odd11 498/2 = 249 odd111 248/2 = 124 even0111 124/2 = 62 even00111 62/2 = 31 odd100111 30/2 = 15 odd1100111 14/2 = 7 odd11100111 6/2 = 3 odd111100111 2/2 = 1 odd1111100111
23
Addition in Binary
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.