Page 1 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Basic Data Types Note that the methods we used to convert from decimal to binary, and back again, work for any base. If, for example we wished to convert to Octal (base 8): Remainder Since the new quotient is 0, collect from last to first =134 8 Check: Number: Position: Value: 1* * * 8 0 = 1* * * 1 = = 92 Octal/Hexadecimal
Page 2 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Basic Data Types Why would I care about octal (base 8) ?? As it turns out, Octal AND Hexadecimal (base 16) are often used because they allow for easy conversion to and from binary. Why is Octal easy ?? Since Octal consists ONLY of the digits 0 through 7, ANY octal digit can be represented using only 3 bits: Octal 0 Binary OctalBinary
Page 3 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Basic Data Types Why is that easy? Consider the binary number (which is and see the previous example) = (Check against Table) Notice that there is a direct transference from binary to octal and octal to binary.
Page 4 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Basic Data Types Example 2: Consider the number Stop and Collect = In Octal ?? = Sure?? = 7 * * * 8080 = 7 * * * 1 = = 457
Page 5 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Basic Data Types What about Hexadecimal (Base 16) ?? Basically, Hex is used for the same reason: It is easy to convert Since 2 4 = 16 pieces of information, we can represent all the digits between 0 and 15: Digit Binary Digit Binary
Page 6 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Basic Data Types But 10, 11, 12, 13, 14, and 15 are NOT digits. They are Combinations of digits. True. We need to substitute the symbols: A = 10 B = 11 C = 12 D = 13 E = 14 F = 15 The Conversion Table Should be: Digit Binary Digit Binary A B C D E F1111
Page 7 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Basic Data Types Once again, consider the binary number = = see the prior example What is the Hexadecimal Value ?? C Sure??? 5C 16 = 5 * C * 16 0 = 5C 16 = 5 * * 16 0 = 5 * * 1 = = 92
Page 8 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Basic Data Types Example 2: Consider the number Stop and Collect = In Hexadecimal ?? E = 1E6 16 Sure?? 1E6 16 = 1 * E * * 16 0 = 1 * * * 16 0 = = 486 = 1 * * * 1
Page 9 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Basic Data Types What about Converting from Octal to Hexadecimal?? The easiest way is to use binary numbers: 57 8 = F= 2F 16 Sure??? = = = Octal 57 Hexadecimal = F 2 2F
Page 10 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft 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 2Go To Slide Index For Chapter 2 Go To Slide Index For Chapter 3Go To Slide Index For Chapter 3 Go To Slide Index For TextbookGo To Slide Index For Textbook Go To Home PageGo To Home Page This Concludes The Slides for this Section Choose an Option: