1. Foundations

Binary And Data

Explain binary number systems, conversions, and how integers and characters are represented in digital systems with fixed-width formats.

Binary and Data

Hi students! 👋 In this lesson, we're going to explore the fascinating world of binary numbers and how computers represent all kinds of data using just 0s and 1s. By the end of this lesson, you'll understand how binary works, how to convert between number systems, and how computers store everything from your favorite songs to text messages using binary code. Get ready to think like a computer! 💻

Understanding the Binary Number System

Let's start with the basics, students! You're probably familiar with the decimal number system (base-10) that we use every day. It uses ten digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. But computers are different - they only understand two states: ON and OFF, which we represent as 1 and 0. This is called the binary number system or base-2 system.

In decimal, each position represents a power of 10. For example, the number 345 means:

  • 3 × 10² + 4 × 10¹ + 5 × 10⁰ = 300 + 40 + 5 = 345

Similarly, in binary, each position represents a power of 2. The binary number 1011 means:

  • 1 × 2³ + 0 × 2² + 1 × 2¹ + 1 × 2⁰ = 8 + 0 + 2 + 1 = 11 in decimal

Here's a fun fact: every time you send a text message, your phone converts each letter into binary code! The letter 'A' becomes 01000001, and 'B' becomes 01000010. Pretty cool, right? 📱

To convert from decimal to binary, students, you can use the division method. Keep dividing by 2 and collect the remainders:

  • 13 ÷ 2 = 6 remainder 1
  • 6 ÷ 2 = 3 remainder 0
  • 3 ÷ 2 = 1 remainder 1
  • 1 ÷ 2 = 0 remainder 1

Reading the remainders from bottom to top gives us 1101, so 13 in decimal equals 1101 in binary! ✨

Representing Integers in Fixed-Width Formats

Now, students, let's talk about how computers actually store numbers. Unlike humans who can write numbers as long as we want, computers have limited space. They use fixed-width formats, meaning they allocate a specific number of bits (binary digits) for each number.

Common fixed-width formats include:

  • 8-bit (1 byte): Can represent 256 different values
  • 16-bit: Can represent 65,536 different values
  • 32-bit: Can represent over 4 billion different values
  • 64-bit: Can represent over 18 quintillion different values

For unsigned integers (positive numbers only), an 8-bit system can represent numbers from 0 to 255. Think of it like having 8 light switches - each can be ON (1) or OFF (0), giving us 2⁸ = 256 possible combinations.

But what about negative numbers? 🤔 That's where two's complement comes in! This is the most common way computers represent signed integers (both positive and negative numbers).

In two's complement for 8-bit numbers:

  • Positive numbers (0 to 127) are represented normally
  • Negative numbers (-1 to -128) use a special encoding

To find the two's complement of a number:

  1. Write the positive number in binary
  2. Flip all the bits (0 becomes 1, 1 becomes 0) - this is called one's complement
  3. Add 1 to the result

For example, to represent -5 in 8-bit two's complement:

  • 5 in binary: 00000101
  • Flip bits: 11111010
  • Add 1: 11111011

So -5 is represented as 11111011! The leftmost bit (1) tells us it's negative. 🔢

Character Representation and Encoding Systems

Here's where it gets really interesting, students! Computers don't just store numbers - they store text, emojis, and all sorts of characters. But remember, computers only understand binary, so we need a way to convert characters into numbers.

ASCII (American Standard Code for Information Interchange) was one of the first character encoding systems. It uses 7 bits to represent 128 different characters, including:

  • Uppercase letters A-Z (65-90)
  • Lowercase letters a-z (97-122)
  • Digits 0-9 (48-57)
  • Special characters like punctuation marks

For example:

  • 'A' = 65 in decimal = 01000001 in binary
  • 'a' = 97 in decimal = 01100001 in binary
  • '0' = 48 in decimal = 00110000 in binary

But ASCII has limitations - it only covers English characters! What about characters from other languages, or emojis? 😊 That's where Unicode comes to the rescue!

Unicode is a much larger character encoding system that can represent over 1 million different characters from virtually every writing system in the world. It includes:

  • Latin, Cyrillic, Arabic, Chinese, Japanese, and Korean characters
  • Mathematical symbols and technical notation
  • Emojis and pictographs
  • Ancient scripts and historical characters

The most common Unicode encoding is UTF-8, which uses 1 to 4 bytes per character. English letters still use 1 byte (like ASCII), but other characters might need more space. For instance, the emoji 😊 requires 4 bytes to store!

Binary Arithmetic and Data Storage

Let's explore how computers perform calculations in binary, students! Binary arithmetic follows similar rules to decimal arithmetic, but it's simpler because we only have two digits.

Binary Addition Rules:

$- 0 + 0 = 0$

$- 0 + 1 = 1 $

$- 1 + 0 = 1$

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

Let's add 1011 (11 in decimal) + 1101 (13 in decimal):

  1011
+ 1101
------
 11000

That gives us 11000 in binary, which equals 24 in decimal (8 + 16 = 24). Perfect! ✅

Here's a mind-blowing fact: your smartphone processes billions of these binary calculations every second! When you take a photo, play a game, or stream a video, it's all happening through binary arithmetic at incredible speeds.

Data Storage Capacity is measured in binary units:

$- 1 Byte = 8 bits$

  • 1 Kilobyte (KB) = 1,024 bytes
  • 1 Megabyte (MB) = 1,024 KB
  • 1 Gigabyte (GB) = 1,024 MB
  • 1 Terabyte (TB) = 1,024 GB

Why 1,024 instead of 1,000? Because computers work in powers of 2! 2¹⁰ = 1,024, which is the closest power of 2 to 1,000. 📊

Conclusion

Congratulations, students! 🎉 You've just learned how computers represent and process all digital information using binary. We explored how the binary number system works with just 0s and 1s, how integers are stored in fixed-width formats using techniques like two's complement for negative numbers, and how characters are encoded using systems like ASCII and Unicode. Remember, every digital device you use - from smartphones to gaming consoles - relies on these fundamental concepts to store and process information. Binary truly is the language that powers our digital world!

Study Notes

• Binary Number System: Base-2 system using only digits 0 and 1, where each position represents a power of 2

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

• Binary to Decimal Conversion: Multiply each digit by its corresponding power of 2 and sum the results

• Fixed-Width Format: Computers allocate a specific number of bits for storing numbers (8-bit, 16-bit, 32-bit, 64-bit)

• Unsigned Integers: Represent only positive numbers; n-bit system can store 0 to (2ⁿ - 1)

• Two's Complement: Method for representing signed integers; flip all bits and add 1 to get negative representation

• ASCII: 7-bit character encoding system representing 128 characters including English letters, digits, and symbols

• Unicode: Extended character encoding system supporting over 1 million characters from all world languages

• UTF-8: Most common Unicode encoding using 1-4 bytes per character

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

• Storage Units: 1 Byte = 8 bits, 1 KB = 1,024 bytes, 1 MB = 1,024 KB, 1 GB = 1,024 MB

• Character Examples: 'A' = 65 = 01000001, 'a' = 97 = 01100001, '0' = 48 = 00110000

Practice Quiz

5 questions to test your understanding

Binary And Data — AS-Level Computer Science | A-Warded