Cover of Code by Charles Petzold - Business and Economics Book

From "Code"

Author: Charles Petzold
Publisher: Microsoft Press
Year: 2000
Category: Computers

🎧 Free Preview Complete

You've listened to your free 10-minute preview.
Sign up free to continue listening to the full summary.

🎧 Listen to Summary

Free 10-min Preview
0:00
Speed:
10:00 free remaining
Chapter 15: Bytes and Hex
Key Insight 2 from this chapter

Hexadecimal Number System

Key Insight

A succinct method for referring to byte values is essential due to their frequent appearance in computer systems; explicit 8-bit binary representations like '10110110' are unwieldy. While decimal equivalents exist, converting them from binary is cumbersome. The octal (base-8) number system offers more brevity, where 3 binary bits convert to 1 octal digit, allowing '10110110' to be '266'. However, octal has a limitation: its representation of multi-byte numbers is inconsistent with individual byte representations because the leftmost octal digit of a byte uses only 2 bits, unlike the other 3-bit digits. This inconsistency necessitates a system where each segment of a byte corresponds to an equal number of bits for coherent multi-byte representations.

The hexadecimal (base-16) number system provides this consistency by dividing each byte into two 4-bit segments, with each segment mapping directly to a single hexadecimal digit. It uses sixteen distinct symbols: 0 through 9, followed by the letters A, B, C, D, E, and F, which represent the decimal values 10 through 15, respectively. This structure simplifies binary-to-hexadecimal conversion: a 4-bit binary sequence directly corresponds to one hexadecimal digit. For example, the binary byte '10110110' is converted by grouping it into '1011' (hex B) and '0110' (hex 6), resulting in 'B6h', with 'h' being a common suffix indicating hexadecimal.

Converting hexadecimal numbers to decimal involves summing the product of each hexadecimal digit's decimal equivalent and its corresponding power of 16. For instance, '9A48Ch' translates to (9 * 16^4) + (10 * 16^3) + (4 * 16^2) + (8 * 16^1) + (12 * 16^0), which equals 631948 in decimal. Decimal to hexadecimal conversion for numbers 255 or smaller typically involves dividing the decimal number by 16 to get a quotient and a remainder, which form the two hexadecimal digits; for example, 182 decimal is 'B6h'. For larger decimal numbers, a multi-division method is used, or the number can be broken down into two bytes, each then converted. Hexadecimal numbers also have defined addition rules using an addition table, and for 8-bit signed values, hexadecimal numbers starting with 8, 9, A, B, C, D, E, or F represent negative values, as their binary equivalents begin with a '1' bit.

📚 Continue Your Learning Journey — No Payment Required

Access the complete Code summary with audio narration, key takeaways, and actionable insights from Charles Petzold.