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
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
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: And, with 4-bits, there are 16 possible combinations:
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 = = = = = = = 1, = = 10, = = 100, = = 1,000, = = 10,000, = = 100,000, = =1,000,000, = =10,000,000, = 1,024
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, = = 100, = = 1,000, = = 10,000, = = 100,000, = = 1,000,000, = = 10,000,000, = 1,024
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) log(2) = log(I) Since = 2 Information Decimals Needed Bits Needed 10 log(10) = log(10)/log(2) = 1.000/ = log(50) = log(50)/log(2) = 1.699/ = log(100) = log(100)/log(2) = 2.000/ = log(500) = log(500)/log(2) = 2.699/ = ,000 log(1000) = log(1000)/log(2) = 3.000/ = ,000 log(10000) = log(10000)/log(2) = 4.000/ = 13.29
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) is 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/ = 3.32 = 4 50 log(50)/log(2) = 1.699/ = 5.64 = log(100)/log(2) = 2.000/ = 6.64 = log(500)/log(2) = 2.699/ = 8.97 = 9 1,000 log(1000)/log(2) = 3.000/ = 9.97 = 10 10,000 log(10000)/log(2) = 4.000/ = = 14
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
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!
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
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: