Digital Number Systems: Binary, Hexadecimal, and BCD
Understanding Number Systems
Number systems are fundamental to computing and digital electronics. They are essentially methods for representing numbers using a specific set of symbols (digits). The key concept differentiating them is the base or radix, which is the total number of unique digits available in that system.
Common Number Systems Breakdown
1. Decimal (Base-10)
This is the number system we use every day.
- Base (Radix): 10
- Digits Used: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
- Concept: Each digit’s position represents a power of 10.
- Example: 12310 = (1 × 102) + (2 × 101) + (3 × 100)
2. Binary (Base-2)
This is the native language of computers because digital circuits use two distinct states: ON/OFF or High/Low voltage, which can be represented by two digits.
- Base (Radix): 2
- Digits Used: 0, 1
- Concept: Each position represents a power of 2. A single binary digit is called a bit.
- Example: 10112 = (1 × 23) + (0 × 22) + (1 × 21) + (1 × 20) = 8 + 0 + 2 + 1 = 1110
3. Octal (Base-8)
Octal is often used as a compact way to represent binary numbers, as three binary digits can be perfectly represented by one octal digit (23 = 8).
- Base (Radix): 8
- Digits Used: 0, 1, 2, 3, 4, 5, 6, 7
- Concept: Each position represents a power of 8.
- Example: 238 = (2 × 81) + (3 × 80) = 16 + 3 = 1910
4. Hexadecimal (Base-16)
Hexadecimal is the most common compact representation for binary in computing (e.g., in memory addresses, color codes, MAC addresses, etc.). It is especially useful because four binary digits (a nibble) fit exactly into one hexadecimal digit (24 = 16).
- Base (Radix): 16
- Digits Used: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
- Note: Where A=10, B=11, C=12, D=13, E=14, F=15 in decimal.
- Concept: Each position represents a power of 16.
- Example: 2A16 = (2 × 161) + (A × 160) = (2 × 16) + (10 × 1) = 32 + 10 = 4210
Key Takeaway: Conversions
The most important aspect of these systems is the ability to convert between them.
| Conversion Type | Method |
|---|---|
| Any Base to Decimal | Multiply each digit by its positional weight (the base raised to the power of the position) and sum the results. |
| Decimal to Any Base | Use the repeated division method: Divide the decimal number by the new base, keep track of the remainders, and read the remainders from bottom to top. |
| Binary to Octal | Group binary digits in sets of three starting from the right. Convert each group to its octal equivalent. |
| Binary to Hexadecimal | Group binary digits in sets of four starting from the right. Convert each group to its hexadecimal equivalent. |
Number System Conversions and BCD
Understanding number system conversions is crucial for working in digital electronics and computer science. The main conversion methods depend on whether you are converting to or from Decimal (Base-10), or converting between binary-related bases (Binary, Octal, Hexadecimal).
1. Conversion Methods
A. To/From Decimal (Base-10)
| Conversion Type | Method | Example |
|---|---|---|
| Any Base (B) → Decimal (10) | Positional Weight: Multiply each digit by its positional weight (Bn) and sum the results. | 10112 → 10: (1 × 23) + (0 × 22) + (1 × 21) + (1 × 20) = 8 + 0 + 2 + 1 = 1110 |
| Decimal (10) → Any Base (B) | Repeated Division: Divide the decimal number by the new base (B). Collect the remainders; the result is the remainders read from bottom (MSB) to top (LSB). | 1310 → 2: 13 ÷ 2 = 6 remainder 1; 6 ÷ 2 = 3 remainder 0; 3 ÷ 2 = 1 remainder 1; 1 ÷ 2 = 0 remainder 1 → 11012 |
B. Conversions Between Binary-Related Bases
Since Octal is 23 and Hexadecimal is 24, conversion to and from Binary is direct by grouping bits.
| Conversion Type | Grouping Method | Example |
|---|---|---|
| Binary → Octal | Group the binary digits into sets of 3, starting from the right (pad with leading zeros if necessary). Convert each group to its octal digit. | 11010112 → 8: (001)(101)(011) → 1538 |
| Binary → Hexadecimal | Group the binary digits into sets of 4, starting from the right. Convert each group to its Hex digit. | 11010112 → 16: (0110)(1011) → 6B16 |
| Octal → Binary | Convert each octal digit into its 3-bit binary equivalent. | 728 → 2: (7)(2) → (111)(010) → 1110102 |
| Hexadecimal → Binary | Convert each Hex digit into its 4-bit binary equivalent. | A516 → 2: (A)(5) → (1010)(0101) → 101001012 |
Tip: To convert Octal ↔ Hexadecimal, always go through Binary as an intermediate step.
2. Binary Coded Decimal (BCD)
The Binary Coded Decimal (BCD) system is a special type of binary encoding used to represent decimal numbers, often found in digital displays like digital clocks, calculators, and meters.
What is BCD?
- Principle: Instead of converting the entire decimal number into its pure binary equivalent, BCD converts each individual decimal digit into its 4-bit binary representation.
- Encoding: The most common form is 8421 BCD (Natural BCD), where the four bits are weighted by 23=8, 22=4, 21=2, and 20=1.
| Decimal Digit | 4-bit BCD Code (8421) |
|---|---|
| 0 | 0000 |
| 1 | 0001 |
| 2 | 0010 |
| 3 | 0011 |
| 4 | 0100 |
| 5 | 0101 |
| 6 | 0110 |
| 7 | 0111 |
| 8 | 1000 |
| 9 | 1001 |
BCD vs. Pure Binary
| Feature | BCD (Binary Coded Decimal) | Pure Binary |
|---|---|---|
| Encoding | Each decimal digit (0-9) is converted separately. | The entire decimal number is converted. |
| Efficiency | Less efficient (wastes 6 of the 16 possible 4-bit combinations: 1010 to 1111 are invalid BCD codes). | More efficient (uses fewer bits to represent larger numbers). |
| Conversion | Easy to convert to and from decimal (human-readable). | More complex calculation for human-readable decimal conversion. |
| Use | Applications requiring easy decimal display (clocks, pocket calculators, financial systems). | General computing, memory, and high-speed processing. |
BCD Conversion Examples
1. Decimal → BCD
Take the decimal number 48510. Convert each digit individually:
| Decimal Digit | 4 | 8 | 5 |
|---|---|---|---|
| BCD Code | 0100 | 1000 | 0101 |
2. BCD → Decimal
Take the BCD number 1001 0011BCD. Group into 4-bit blocks and convert each block:
| 4-bit Block | 1001 | 0011 |
|---|---|---|
| Decimal Equivalent | 9 | 3 |
BCD is a method of representing each decimal digit (0 through 9) using its own four-bit binary code. Here is a breakdown of the types mentioned:
Types of BCD and Digital Codes
1. Natural Binary Code (NBCD / 8421 Code)
- Definition: This is the most common form of BCD. Each decimal digit is represented by its natural, 4-bit, unweighted binary equivalent.
- Weighted Code Status: It is a Weighted Code.
- Weights: The bit positions have the weights 8, 4, 2, and 1, from most significant bit (MSB) to least significant bit (LSB).
- Example: Decimal 5 is 0101 (which is 0 × 8 + 1 × 4 + 0 × 2 + 1 × 1 = 5).
2. Weighted Codes
- Definition: In a weighted code, each bit position in the four-bit group is assigned a specific numerical weight. The decimal value is the sum of the products of each bit and its weight.
- Examples:
- 8421 (Natural BCD)
- 2421
- 7421
- 84-2-1 (Codes like 2421 and 84-2-1 are often designed to be self-complementing).
3. Self-Complementing Codes
- Definition: A code is self-complementing if the 1’s complement of the binary code for a decimal digit D is equal to the code for the digit’s 9’s complement (9 – D). This property simplifies subtraction operations.
- Condition: A necessary condition for a weighted code to be self-complementing is that the sum of the weights must equal 9.
- Examples: 2421, 84-2-1 (weighted), and Excess-3 (non-weighted).
- Excess-3: This is a non-weighted code derived by adding 3 (00112) to the Natural BCD (8421) code of the digit.
4. Cyclic Codes (Unit Distance Codes)
- Definition: A code is called a cyclic code (or unit distance code) if successive code words for consecutive decimal digits differ in only one bit position.
- Application: These codes are useful in applications where a change in an input value must not cause a momentary flash of incorrect codes, such as in rotary encoders.
- Example: The most common example is the Gray Code, which is a non-weighted, cyclic code. While BCD itself is a category for decimal encoding, Gray code is the most relevant example of a cyclic code in the context of digital codes. Note: The BCD codes (like 8421) themselves are not cyclic.
