Key Takeaways
- Hexadecimal is a base-16 number system using digits 0-9 and letters A-F
- Each hex digit represents 4 binary bits (a "nibble")
- Two hex digits can represent values from 0 to 255 (00 to FF)
- Widely used in computing for colors, memory addresses, and data representation
- Convert to decimal by multiplying each digit by powers of 16
Understanding Hexadecimal Numbers
| Hex | Decimal | Binary | Notes |
|---|---|---|---|
| 00 | 0 | 00000000 | Minimum value (null, black in RGB) |
| 0F | 15 | 00001111 | Highest single hex digit |
| 10 | 16 | 00010000 | First two-digit hex value |
| 1F | 31 | 00011111 | — |
| 3F | 63 | 00111111 | — |
| 40 | 64 | 01000000 | — |
| 7F | 127 | 01111111 | Signed byte maximum positive value |
| 80 | 128 | 10000000 | Signed byte becomes negative here |
| A0 | 160 | 10100000 | — |
| C0 | 192 | 11000000 | Common subnet mask byte |
| FF | 255 | 11111111 | Maximum byte value (white in RGB) |
| Note: In hex, each digit represents 4 bits (a "nibble"). Two hex digits represent one byte (8 bits, values 0–255). This is why hex is so common in computing — it maps perfectly to bytes. IPv4 addresses, RGB colors, memory addresses, and machine code are all commonly expressed as hex bytes. | |||
| Base | Name | Digits Used | Example (decimal 255) | Common Use |
|---|---|---|---|---|
| Base 2 | Binary | 0, 1 | 11111111 | CPU instructions, bit flags, boolean logic |
| Base 8 | Octal | 0–7 | 377 | Unix file permissions (chmod 755), older systems |
| Base 10 | Decimal | 0–9 | 255 | Human counting; everyday arithmetic |
| Base 16 | Hexadecimal | 0–9, A–F | FF | Memory addresses, RGB colors, MAC addresses, HTML colors |
| Base 64 | Base64 | A–Z, a–z, 0–9, +, / | /w== | Encoding binary data in text (email attachments, JWTs) |
| Note: Prefix conventions: binary = 0b (e.g., 0b11111111); octal = 0o or leading 0 (e.g., 0o377); hexadecimal = 0x (e.g., 0xFF). In HTML/CSS, hex colors use # prefix (e.g., #FF5733). The "0x" prefix is used in C, Python, JavaScript, and most programming languages to denote hexadecimal literals. | ||||
| Value | Hex | Common Context | Notes |
|---|---|---|---|
| 255 (max byte) | 0xFF | RGB color max, subnet masks | 11111111 in binary — all bits set |
| 256 (byte overflow) | 0x100 | First 3-digit hex value | Powers of 2 shift left in hex |
| 4,096 | 0x1000 | Memory page size (4KB) | 2^12 |
| 65,535 | 0xFFFF | Max 16-bit unsigned integer | Two full bytes |
| 65,536 | 0x10000 | First 5-digit hex | 2^16 |
| 16,777,215 | 0xFFFFFF | Max 24-bit value; max RGB color (#FFFFFF = white) | Three full bytes |
| 2,147,483,647 | 0x7FFFFFFF | Max 32-bit signed integer | Int32 maximum |
| 4,294,967,295 | 0xFFFFFFFF | Max 32-bit unsigned integer | UInt32 maximum |
| 0 | 0x00 | Null, black (#000000), false | All bits cleared |
| 127 | 0x7F | Max signed 8-bit integer | Int8 maximum |
| Note: Powers of 16 are particularly clean in hex: 16^1 = 0x10; 16^2 = 0x100; 16^3 = 0x1000; 16^4 = 0x10000. This is analogous to how powers of 10 work in decimal. Each additional hex digit multiplies the range by 16. | |||
Hexadecimal numbers are a base-16 numeral system that is widely used in computing and digital systems. In hexadecimal, the digits range from 0 to 9, followed by the letters A to F, which represent values 10 to 15 respectively. This allows for concise representation of binary data.
Hex to Decimal: Multiply each digit by 16^position
Hexadecimal Digit Values
| Hex | Decimal | Hex | Decimal |
|---|---|---|---|
| 0 | 0 | 8 | 8 |
| 1 | 1 | 9 | 9 |
| 2 | 2 | A | 10 |
| 3 | 3 | B | 11 |
| 4 | 4 | C | 12 |
| 5 | 5 | D | 13 |
| 6 | 6 | E | 14 |
| 7 | 7 | F | 15 |
Hexadecimal to Decimal Conversion
Converting a hexadecimal number to decimal involves multiplying each digit by the corresponding power of 16 and summing the results. Let's consider an example:
Hex: 3A
Decimal to Hexadecimal Conversion
Converting a decimal number to hexadecimal involves dividing the decimal number by 16 repeatedly and noting the remainders. The hexadecimal representation is obtained by writing the remainders in reverse order.
Decimal: 172
10 / 16 = 0 remainder 10 (A)
Hex: AC
Arithmetic Operations with Hexadecimal Numbers
Addition in Hexadecimal
Adding hexadecimal numbers follows similar rules to decimal addition. When adding digits, if the sum is greater than or equal to 16, a carry occurs.
Hex: AB + 2F = DA
A(10) + 2 + 1(carry) = 13 = D
Result: DA
Subtraction in Hexadecimal
Subtracting hexadecimal numbers is similar to decimal subtraction. If the value being subtracted is greater than the value being subtracted from, a borrow occurs from the next higher digit.
Multiplication in Hexadecimal
Multiplying hexadecimal numbers involves multiplying each digit and summing the results. If the result is greater than or equal to 16, a carry occurs.
Division in Hexadecimal
Dividing hexadecimal numbers is similar to decimal division. The division process is performed digit by digit, and if the dividend is less than the divisor, a zero is added to the quotient.
Applications of Hexadecimal Numbers
Hexadecimal numbers have various applications in different fields, including math, science, and everyday life:
Computer Science and Programming
Hexadecimal is extensively used in computer science and programming. It provides a concise representation of binary data, making it ideal for low-level programming, memory addressing, bitwise operations, and debugging.
Color Representation
Hexadecimal plays a vital role in representing colors in digital systems. Each color component (red, green, blue) is typically represented by two hex digits, allowing for a wide range of colors to be expressed. For example, #FF5733 represents a shade of orange.
Network Administration
Hexadecimal is used in network administration for tasks such as configuring IP addresses, subnet masks, and port numbers. It provides a compact and efficient representation of these values.
Memory Addressing
Hexadecimal is extensively used in memory addressing. Memory addresses are typically represented in hex format, allowing for efficient allocation and referencing of memory locations.
Cryptography
Hexadecimal plays a significant role in cryptography. Cryptographic algorithms often utilize hex representations for keys, cipher text, and other cryptographic elements. Hex is used to represent binary data in a more manageable and human-readable format.
Web Development
In web development, hexadecimal values are commonly used to represent colors in Cascading Style Sheets (CSS) and other web-related technologies. Hexadecimal color codes provide a wide range of color choices and are widely supported across browsers and platforms.
Conclusion
Hexadecimal numbers are a fundamental part of computing, digital systems, and various applications across multiple fields. Understanding how to convert hexadecimal numbers, perform arithmetic operations, and grasp their practical applications is essential for professionals in computer science, programming, digital electronics, and other related disciplines.