Chapter 1 6 min read
Save

Number Systems and Codes

Digital Logic Systems · BCA · Updated Apr 06, 2026

Table of Contents

Chapter 1: Number Systems and Codes

Introduction to Number Systems

When you start learning digital electronics, understanding number systems is absolutely fundamental. We're not just talking about the decimal (base-10) system you use every day. Digital systems work primarily with binary, but to make things easier for us humans and for practical engineering applications, we also use octal and hexadecimal systems. Each has its own advantages, and knowing when to use each one will make you a much better digital electronics engineer.

1. Binary System (Base-2)

What is Binary?

Binary is the native language of digital systems. It uses only two digits: 0 and 1. In computing, these represent the absence (0) or presence (1) of electrical voltage. Every number, letter, image, and sound in a computer is ultimately represented using just these two symbols.

Binary Counting

Counting in binary follows the same principle as decimal, but we only have 0 and 1 available. The rightmost bit represents 2^0 (ones place), the next represents 2^1 (twos place), then 2^2 (fours place), and so on. To count: 0 (0), 1 (1), 10 (2), 11 (3), 100 (4), 101 (5), 110 (6), 111 (7), 1000 (8), and so on.

Converting Decimal to Binary

To convert a decimal number to binary, repeatedly divide by 2 and collect the remainders. For example, to convert 13 to binary: 13 ÷ 2 = 6 R1, 6 ÷ 2 = 3 R0, 3 ÷ 2 = 1 R1, 1 ÷ 2 = 0 R1. Reading the remainders from bottom to top: 1101. We can verify: 1×8 + 1×4 + 0×2 + 1×1 = 13. Correct!

Converting Binary to Decimal

Converting binary to decimal is straightforward multiplication and addition. For binary 1011: (1×2^3) + (0×2^2) + (1×2^1) + (1×2^0) = 8 + 0 + 2 + 1 = 11.

2. Octal System (Base-8)

What is Octal?

Octal uses eight digits: 0-7. It's particularly useful because 8 = 2^3, meaning each octal digit represents exactly three binary digits. This makes conversion between binary and octal very convenient—useful for computer memory addresses and permissions.

Binary to Octal Conversion

To convert binary to octal, group the binary digits into sets of three from right to left. For binary 101110: group as 101 110. Then convert each group: 101 (binary) = 5 (octal), 110 (binary) = 6 (octal). Result: 56 (octal).

Octal to Binary Conversion

Reverse the process. Each octal digit becomes three binary digits. Octal 47: 4 = 100 (binary), 7 = 111 (binary). Result: 100111 (binary).

3. Hexadecimal System (Base-16)

What is Hexadecimal?

Hexadecimal uses 16 symbols: 0-9 and A-F (where A=10, B=11, C=12, D=13, E=14, F=15). Since 16 = 2^4, each hexadecimal digit represents exactly four binary digits. This makes hexadecimal extremely popular for representing memory addresses, color codes in graphics, and machine code in assembly language.

Binary to Hexadecimal Conversion

Group binary digits into sets of four from right to left. Binary 11010110: group as 1101 0110. Convert: 1101 = D (hex), 0110 = 6 (hex). Result: D6 (hex).

Hexadecimal to Binary Conversion

Each hexadecimal digit becomes four binary digits. Hex 2F: 2 = 0010, F = 1111. Result: 00101111 (binary).

Converting Decimal to Hexadecimal

Repeatedly divide by 16 and collect remainders. For 255: 255 ÷ 16 = 15 R15 (F), 15 ÷ 16 = 0 R15 (F). Reading upward: FF (hex). Verification: F×16 + F = 15×16 + 15 = 255. Correct!

4. Complements: 1's and 2's Complement

Understanding Complements

Complements are used to represent negative numbers in binary and to perform subtraction using addition. The two types we care about are 1's complement and 2's complement.

1's Complement

The 1's complement of a binary number is found by flipping every bit—changing all 0s to 1s and all 1s to 0s. For 4-bit binary, the 1's complement of 0101 (5) is 1010 (-5 in 1's complement). Problem: 1's complement has two representations for zero: 0000 and 1111. This is awkward!

2's Complement

2's complement fixes the zero problem. It's calculated as: 2's complement = 1's complement + 1. For 0101 (5), the 1's complement is 1010, and adding 1 gives 1011 (which represents -5 in 2's complement). Now there's only one representation for zero: 0000. This is why 2's complement is universally used in modern systems.

Using 2's Complement for Subtraction

Instead of building a subtractor circuit, we can use an adder! To calculate A - B, we add A + 2's complement of B. For 5 - 3 with 4-bit numbers: 0101 + 1101 = 10010. Ignoring the overflow carry bit: 0010 (which is 2). Correct!

5. Binary Coded Decimal (BCD)

What is BCD?

BCD represents each decimal digit (0-9) using four binary bits. It's useful in applications that need to display decimal numbers, like digital clocks and calculators. The key advantage: it's easy to convert between decimal and BCD for human interfaces.

BCD Encoding

Each decimal digit gets its own 4-bit code: 0=0000, 1=0001, 2=0010, 3=0011, 4=0100, 5=0101, 6=0110, 7=0111, 8=1000, 9=1001. For decimal 47, we encode as: 4 = 0100, 7 = 0111. Result in BCD: 0100 0111.

Advantages and Limitations

BCD makes decimal-to-binary conversion trivial—each digit converts independently. However, BCD numbers are less efficient than pure binary. For example, 256 requires 9 bits in BCD (0010 0101 0110) but only 8 bits in pure binary (100000000). BCD arithmetic is also more complex than binary arithmetic.

6. Gray Code (Reflected Binary Code)

What is Gray Code?

Gray code is a binary numbering system where consecutive values differ by only one bit. This is crucial in applications like rotary encoders and digital-to-analog converters, where transitioning between values might cause errors if multiple bits change simultaneously.

Binary to Gray Code Conversion

The MSB (most significant bit) remains the same. Each subsequent bit is the XOR of the previous binary bit and current binary bit. For binary 1011: MSB stays 1, then 1 XOR 0 = 1, 0 XOR 1 = 1, 1 XOR 1 = 0. Gray code: 1110.

Gray Code to Binary Conversion

The MSB stays the same. Each subsequent binary bit is the XOR of the previous binary bit and current gray code bit. Working through the conversion is more intuitive when you practice it several times.

7. Parity for Error Detection

Simple Parity Check

Parity is a simple error-detection mechanism. We add one extra bit to a group of data bits. Even parity means the total number of 1s (including the parity bit) should be even; odd parity means it should be odd. For example, with even parity, if our data is 1011, we add a parity bit to make the total number of 1s even: 10110.

Limitations

Parity can only detect single-bit errors, not correct them. If two bits flip, parity won't catch the error. For applications requiring error correction, we use Hamming codes or more sophisticated schemes.

Conclusion

Mastering number systems is essential for digital electronics. Binary is what the hardware understands, but octal and hexadecimal make large binary numbers manageable for humans. Complements let us handle negative numbers and subtraction elegantly. BCD and Gray code solve specific real-world problems. And parity provides basic error detection. Build strong intuition with these systems, and digital logic design becomes much clearer.

Related Notes

Discussion

0 comments

Join the discussion

Log in to share your thoughts and help fellow students.

Log in to comment

No comments yet. Be the first to share your thoughts!