Presentation is loading. Please wait.

Presentation is loading. Please wait.

Page 1 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Bits & Bytes OR OffOn Bit = Binary Digit (or Binary Digit) = {0, 1} Bits.

Similar presentations


Presentation on theme: "Page 1 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Bits & Bytes OR OffOn Bit = Binary Digit (or Binary Digit) = {0, 1} Bits."— Presentation transcript:

1

2 Page 1 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Bits & Bytes OR OffOn Bit = Binary Digit (or Binary Digit) = {0, 1} Bits Assume you wish to send a message using a Light Switch A binary condition since the light switch can be either: Any binary condition can be represented with a single light switch : Good OR Bad Yes OR No Male OR Female Dead OR Alive

3 Page 2 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft But, what if there are more than two states? What if I want to represent the conditions GOOD, SO-SO, and BAD???? Add more Light SwitchesSimple ….. If there are 2 light switches, the total combinations are: #1#2#3#4 Off 0 Off 0 Off 0 On 1 Off 0 On 1 On 1 On 1 Interpreted as: Bad Interpreted as: So-So Interpreted as: Good Not Used

4 Page 3 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Bits and Bytes If I can transmit 4 messages with two bits, how many could I transmit if I had 3 bits? Or 4 bits? With 3-bits, there are 8 possible combinations: 000 100 001101 010110 011111 And, with 4-bits, there are 16 possible combinations: 0000 010010001100 0001010110011101 0010011010101110 0011011111001111

5 Page 4 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Bits and Bytes Is there any way to know how many messages we could transmit for a given number of bits without having to test all possible combinations?? As in Decimal (base 10), it is possible to determine how many messages can be transmitted for any number of decimal places. In Binary (base 2), the same calculations are made, but using bits (instead of decimals). Decimal Number Number Number Places Messages Bits Messages 0 10 0 = 102 0 = 1 110 1 = 1012 1 = 2 210 2 = 10022 2 = 4 310 3 = 1,00032 3 = 8 410 4 = 10,00042 4 = 16 5 10 5 = 100,0052 5 = 32 6 10 6 = 1,000,00062 6 = 64 7 10 7 = 10,000,00072 7 = 128 810 8 = 100,000,00082 8 = 256 910 9 =1,000,000,00092 9 = 512 1010 10 =10,000,000,000 102 10 = 1,024

6 Page 5 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Bits and Bytes The General formula is: I = B n where: I = The amount of Information (messages) available B = The base we are working in (Decimal or Binary) n = The number of digits (decimals or bits) we have Applying the formula to both decimal and binary values: 10 0 = 12 0 = 1 10 1 = 102 1 = 2 10 2 = 1002 2 = 4 10 3 = 1,0002 3 = 8 10 4 = 10,0002 4 = 16 10 5 = 100,0002 5 = 32 10 6 = 1,000,0002 6 = 64 10 7 = 10,000,0002 7 = 128 10 8 = 100,000,0002 8 = 256 10 9 = 1,000,000,0002 9 = 512 10 10 = 10,000,000,0002 10 = 1,024

7 Page 6 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Bits and Bytes What if I Know how much information (I = Number of Messages) I want to transmit. How do I determine the number of bits I need? Just reverse the process. If I = 10 n (decimal) OR I = 2 n (binary) then log(I) = n log(10) log(I) = n log(2) log(I) log(I) log(I) log(I) And n = = n = = log(10) 1.000 log(2) 0.30103 = log(I) Since 10 0.30103 = 2 Information Decimals Needed Bits Needed 10 log(10) = 1.000 log(10)/log(2) = 1.000/.30103 = 3.32 50 log(50) = 1.699 log(50)/log(2) = 1.699/.30103 = 5.64 100 log(100) = 2.000 log(100)/log(2) = 2.000/.30103 = 6.64 500 log(500) = 2.699 log(500)/log(2) = 2.699/.30103 = 8.97 1,000 log(1000) = 3.000 log(1000)/log(2) = 3.000/.30103 = 9.97 10,000 log(10000) = 4.000 log(10000)/log(2) = 4.000/.30103 = 13.29

8 Page 7 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Bits and Bytes How can we have partial bits (or decimals)? For example, how can we have 5.64 bits to represent 50 messages? We Can’t The formula given should have been: log(I) log(I) Where: n = = log(2) 0.30103is the ceiling of the result (i.e., rounded up) And the number of bits needed would be: Messages Bits Needed 10 log(10)/log(2) = 1.000/.30103 = 3.32 = 4 50 log(50)/log(2) = 1.699/.30103 = 5.64 = 6 100 log(100)/log(2) = 2.000/.30103 = 6.64 = 7 500 log(500)/log(2) = 2.699/.30103 = 8.97 = 9 1,000 log(1000)/log(2) = 3.000/.30103 = 9.97 = 10 10,000 log(10000)/log(2) = 4.000/.30103 = 13.29 = 14

9 Page 8 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Bits and Bytes Notice that we could have predicted that, for example, it would take 6 bits to represent 50 pieces of information since: 2 5 = 32 and 2 6 = 64 If we need 6 bits to represent 50 pieces of information, and we could represent 64 pieces of information, what happens to the remaining 16 pieces of information? They either remain unused, or are available for future use

10 Page 9 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Bits and Bytes What does this have to do with Computers? If we were to look inside a computer (especially earlier ones) we might see a series of ‘doughnuts’: Which were merely metal rings with wires running through them Depending on whether there was voltage running through them or not (actually, high voltage or low voltage) the series represented a sequence of messages. A BINARY SITUATION!

11 Page 10 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Bits and Bytes Notice that since there are 5 ‘doughnuts’, there are 2 5 or 32 Combinations Where and represent the different voltage states

12 Page 11 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft This Concludes The Slides for this Section  Repeat Slides for this SectionRepeat Slides for this Section  Go To Next Set of Slides For this ChapterGo To Next Set of Slides For this Chapter  Go To Slide Index For Chapter 1Go To Slide Index For Chapter 1  Go To Slide Index For Chapter 2Go To Slide Index For Chapter 2  Go To Slide Index For TextbookGo To Slide Index For Textbook  Go To Home PageGo To Home Page Choose an Option:


Download ppt "Page 1 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Bits & Bytes OR OffOn Bit = Binary Digit (or Binary Digit) = {0, 1} Bits."

Similar presentations


Ads by Google