1. Digital Logic

Number Systems

Binary, octal, decimal, and hexadecimal representations, conversions, signed numbers, and binary arithmetic fundamentals for digital systems.

Number Systems

Hey students! 👋 Welcome to one of the most fundamental concepts in computer engineering - number systems! This lesson will help you understand how computers "think" and process information using different numerical representations. By the end of this lesson, you'll master binary, octal, decimal, and hexadecimal systems, learn how to convert between them, understand how computers handle negative numbers, and perform basic binary arithmetic. Think of this as learning the secret language that makes every digital device around you work! 💻

Understanding Different Number Systems

Let's start with something you already know perfectly - the decimal system! Every day, you use base-10 numbers without even thinking about it. When you see the number 247, your brain automatically understands this as 2×10² + 4×10¹ + 7×10⁰ = 200 + 40 + 7. This positional notation is the key to understanding all number systems! 🔢

Binary (Base-2) is the foundation of all digital systems. Computers use binary because digital circuits can only be in two states: ON (1) or OFF (0). Just like a light switch! Every piece of data in your smartphone, laptop, or gaming console is ultimately stored and processed as sequences of 1s and 0s. For example, the binary number 1011 represents 1×2³ + 0×2² + 1×2¹ + 1×2⁰ = 8 + 0 + 2 + 1 = 11 in decimal.

Octal (Base-8) uses digits 0 through 7. While less common today, it was historically important in computer systems because 8 is a power of 2 (2³), making conversion to binary straightforward. Each octal digit corresponds to exactly three binary digits. For instance, octal 17 equals 1×8¹ + 7×8⁰ = 8 + 7 = 15 in decimal.

Hexadecimal (Base-16) is incredibly popular in computer engineering! It uses digits 0-9 and letters A-F (where A=10, B=11, C=12, D=13, E=14, F=15). Hexadecimal is perfect for representing binary data compactly - each hex digit represents exactly four binary digits. This is why you see hex codes like #FF5733 for colors in web design, or memory addresses like 0x2A4B in programming! 🎨

Converting Between Number Systems

Converting between these systems is like translating between different languages - once you know the rules, it becomes second nature! Let's explore the most effective methods.

Decimal to Binary Conversion uses the division method. Take decimal 25: divide by 2 repeatedly and collect remainders from bottom to top. 25÷2=12 remainder 1, 12÷2=6 remainder 0, 6÷2=3 remainder 0, 3÷2=1 remainder 1, 1÷2=0 remainder 1. Reading upward: 11001₂. You can verify: 1×16 + 1×8 + 0×4 + 0×2 + 1×1 = 25! ✅

Binary to Decimal is straightforward - multiply each digit by its position value and sum them up. For 110110₂: 1×32 + 1×16 + 0×8 + 1×4 + 1×2 + 0×1 = 32 + 16 + 4 + 2 = 54₁₀.

Hexadecimal conversions are super useful in practice! To convert decimal 255 to hex: 255÷16=15 remainder 15. Since 15 in hex is F, we get FF₁₆. That's why 255 is often seen as FF in computer systems - it's the maximum value for an 8-bit byte! This appears everywhere from RGB color values to memory dumps in debugging.

Quick conversion tricks: Binary to hex is easy - group binary digits in sets of four from right to left, then convert each group. For example, 11010110₂ becomes 1101|0110, which converts to D6₁₆. Similarly, for octal, group in sets of three!

Signed Numbers and Two's Complement

Here's where things get really interesting, students! How do computers represent negative numbers when they only understand 1s and 0s? 🤔

The most elegant solution is Two's Complement, used by virtually all modern computers. In an 8-bit system, the leftmost bit is the sign bit. If it's 0, the number is positive; if it's 1, the number is negative. But here's the clever part - negative numbers aren't just positive numbers with a sign bit flipped!

To find the two's complement of a number (making it negative), you flip all the bits (called one's complement) and add 1. Let's say we want -5 in 8-bit two's complement:

  • Start with +5: 00000101
  • Flip all bits: 11111010
  • Add 1: 11111011

So -5 is represented as 11111011. This system is brilliant because it allows the same addition circuits to work for both positive and negative numbers! When you add 5 + (-5), you get 00000101 + 11111011 = 100000000, and the overflow bit is discarded, leaving 00000000 (zero). Perfect! 🎯

The range for 8-bit two's complement is -128 to +127. Notice it's not symmetric - there's one more negative number than positive because zero takes up one of the positive slots.

Binary Arithmetic Fundamentals

Binary arithmetic follows the same principles as decimal arithmetic, but it's actually simpler because you only deal with 1s and 0s! Let's master the basics that make every calculator, smartphone, and computer work.

Binary Addition rules are straightforward:

$- 0 + 0 = 0$

$- 0 + 1 = 1 $

$- 1 + 0 = 1$

  • 1 + 1 = 10 (that's 0 with a carry of 1)

Let's add 1011₂ + 1101₂:

  1011
+ 1101
------
 11000

Starting from the right: 1+1=10 (write 0, carry 1), 1+0+1(carry)=10 (write 0, carry 1), 0+1+1(carry)=10 (write 0, carry 1), 1+1+1(carry)=11 (write 1, carry 1). Result: 11000₂ = 24₁₀.

Binary Subtraction can be tricky with borrowing, so computers typically use addition with two's complement instead. To compute 12 - 5, computers calculate 12 + (-5) using the two's complement of 5.

Overflow is a critical concept in digital systems. When the result of an operation exceeds the number of bits available, overflow occurs. In 4-bit arithmetic, 1111₂ + 0001₂ should equal 10000₂, but we only have 4 bits, so we get 0000₂ instead. This is why your calculator might give unexpected results with very large numbers!

Understanding these fundamentals helps you grasp why computers have limitations and why programmers need to be careful about data types and ranges in their code.

Conclusion

Congratulations, students! You've just mastered the numerical foundation of all digital technology! 🎉 We've explored how binary serves as the universal language of computers, learned efficient conversion techniques between decimal, binary, octal, and hexadecimal systems, discovered how two's complement elegantly handles negative numbers, and understood the basic arithmetic operations that power every digital calculation. These concepts aren't just academic - they're the building blocks that make your smartphone apps, video games, and even this online lesson possible. Every time you see a hex color code, a binary file, or wonder how computers process negative numbers, you'll now understand the elegant mathematics behind it all!

Study Notes

• Number System Bases: Decimal (10), Binary (2), Octal (8), Hexadecimal (16) - each position represents a power of the base

• Binary to Decimal: Multiply each digit by 2^position and sum: 1011₂ = 1×8 + 0×4 + 1×2 + 1×1 = 11₁₀

• Decimal to Binary: Divide by 2 repeatedly, collect remainders from bottom to top

• Hexadecimal Digits: 0-9 and A(10), B(11), C(12), D(13), E(14), F(15)

• Binary-Hex Conversion: Group binary in sets of 4 digits, each group = 1 hex digit

• Binary-Octal Conversion: Group binary in sets of 3 digits, each group = 1 octal digit

• Two's Complement: Flip all bits and add 1 to get negative representation

• 8-bit Two's Complement Range: -128 to +127

• Binary Addition Rules: 0+0=0, 0+1=1, 1+0=1, 1+1=10 (carry 1)

• Overflow: Occurs when result exceeds available bits

• Sign Bit: Leftmost bit in signed numbers (0=positive, 1=negative)

• Common Values: 255₁₀ = FF₁₆ = 11111111₂ (maximum 8-bit value)

Practice Quiz

5 questions to test your understanding

Number Systems — Computer Engineering | A-Warded