Welcome to the World of Binary!

Hello! Today we are diving into the Binary Number System. This is a fundamental part of your AQA AS Level Computer Science course under the "Fundamentals of data representation" section. Don't worry if you’ve always found math a bit scary; binary is actually very logical and much simpler than the decimal system we use every day. By the end of these notes, you’ll be reading and calculating like a computer!

Why learn this? Computers are made of billions of tiny switches that can only be "on" or "off." Because there are only two states, we use Base 2 (binary) to represent everything—from your favorite video game to the text you're reading right now.

1. Unsigned Binary

Unsigned binary numbers are used to represent positive integers (whole numbers) only. They cannot represent negative numbers.

How it works: Place Values

In our normal decimal system (Base 10), we have columns for units, tens, hundreds, and so on. In binary, each column is a power of 2.

For an 8-bit number (a byte), the place values are:
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1

Converting Binary to Decimal

To convert a binary number like 10100100 to decimal, just add up the values where there is a "1":
• (1 x 128) + (0 x 64) + (1 x 32) + (0 x 16) + (0 x 8) + (1 x 4) + (0 x 2) + (0 x 1)
• \( 128 + 32 + 4 = 164 \)

Converting Decimal to Binary

The "Subtraction Method":
1. Find the largest power of 2 that fits into your number.
2. Put a 1 in that column and subtract the value from your total.
3. Repeat for the remainder until you reach zero.

Quick Review: Min and Max Values
For \( n \) bits:
• The minimum value is always 0.
• The maximum value is \( 2^n - 1 \).
Example: With 8 bits, the max is \( 2^8 - 1 = 255 \).

Key Takeaway: Binary is just a different way of counting where you only have two digits: 0 and 1. The "unsigned" version is only for zero and positive numbers.

2. Unsigned Binary Arithmetic

Computers need to do math, too! You need to know how to add and multiply unsigned binary integers.

Binary Addition

Addition follows four simple rules:
• \( 0 + 0 = 0 \)
• \( 0 + 1 = 1 \)
• \( 1 + 1 = 0 \) (carry 1 to the next column)
• \( 1 + 1 + 1 = 1 \) (carry 1 to the next column)

Common Mistake: Forgetting the "carry." Always write your carries clearly above the next column so you don't lose them!

Binary Multiplication

Binary multiplication is actually easier than decimal multiplication because you are only ever multiplying by 0 or 1. It’s essentially "shift and add."
Example: \( 101 \times 11 \)
1. Multiply 101 by the first '1' (from the right): 101
2. Multiply 101 by the next '1', but shift it left: 1010
3. Add them together: \( 101 + 1010 = 1111 \).

Key Takeaway: If you can add 1+1, you can do binary arithmetic. Just take it one column at a time.

3. Signed Binary (Two's Complement)

What if we need to represent negative numbers? We use a system called Two's Complement.

The Magic of the Most Significant Bit (MSB)

In Two's Complement, the furthest bit to the left (the MSB) becomes negative. For an 8-bit number, the columns look like this:
-128 | 64 | 32 | 16 | 8 | 4 | 2 | 1

How to make a number negative

If you have a positive number (e.g., 5) and want to make it negative (-5):
1. Write the positive number in binary: 00000101
2. Flip all the bits (change 0s to 1s and 1s to 0s): 11111010
3. Add 1 to the result: 11111011
Memory Aid: "Flip and Fill" — Flip the bits and fill it with one more!

Binary Subtraction

In computer science, we don't really "subtract." Instead, we add a negative number.
To do \( 10 - 4 \), you calculate \( 10 + (-4) \) using Two's Complement for the -4.

Range of Signed Binary

For \( n \) bits, the range is:
Min: \( -2^{n-1} \)
Max: \( 2^{n-1} - 1 \)
Example: With 8 bits, the range is -128 to +127.

Did you know? Two's complement is used because it allows the CPU to use the same addition hardware for both positive and negative numbers. It's very efficient!

Key Takeaway: Two's Complement lets us represent negative numbers by making the leftmost column negative.

4. Numbers with a Fractional Part (Fixed Point)

Sometimes we need to represent decimals (like 10.5). We use Fixed Point Binary for this.

The Binary Point

We imagine a "binary point" (like a decimal point) at a fixed position. The columns to the right of the point are fractions (halves, quarters, eighths...).

Example of an 8-bit fixed point number with 4 bits for the whole part and 4 bits for the fractional part:
8 | 4 | 2 | 1 | . | 0.5 | 0.25 | 0.125 | 0.0625

Conversion Example

To represent 6.75 in binary:
1. The whole part (6) is: \( 4 + 2 \), which is 0110
2. The fractional part (0.75) is: \( 0.5 + 0.25 \), which is 1100
3. Result: 0110.1100

Don't worry if this seems tricky! Just remember that every time you move one column to the right, you are simply dividing by 2, just like every time you move left, you multiply by 2.

Key Takeaway: Fixed point binary uses specific columns to represent values less than 1. The position of the point never moves!

Final Quick Review

Unsigned: Positive numbers only. Max = \( 2^n - 1 \).
Two's Complement: Allows negative numbers. Leftmost bit is negative.
Arithmetic: \( 1+1 = 0 \) carry 1. Subtraction is just adding a negative.
Fixed Point: Use columns like 0.5, 0.25, etc., to represent fractions.

You've got this! Binary is the foundation of everything you will learn in Computer Science. Keep practicing these conversions and they will become second nature.