Introduction to Binary and Decimal

Welcome to your study notes for Binary and Decimal Numbers! In CCEA AS Level Digital Technology (AS 2: Fundamentals of Digital Technology), understanding how data is represented is the foundation for everything else you will study. Don't worry if working with ones and zeros seems unusual at first—once you master a few straightforward rules, you will be able to convert and calculate numbers with confidence!

Why do computers use binary?
Humans use base-\(10\) (denary) every day, likely because we have \(10\) fingers. Computers, however, are made up of millions of tiny electronic switches called transistors. A transistor can easily detect two distinct physical states: OFF (low voltage, represented by \(0\)) or ON (high voltage, represented by \(1\)). Using binary (base-\(2\)) makes electronic circuits cheaper, simpler, and far less prone to errors or electrical noise.

Did you know? A single binary digit is called a bit (short for Binary digit). A group of \(4\) bits is called a nibble, and a group of \(8\) bits is called a byte.

1. Understanding Number Bases

Denary (Decimal / Base-\(10\))

In our everyday system, we use ten digits: \(0, 1, 2, 3, 4, 5, 6, 7, 8,\) and \(9\). Each column moving to the left increases by a power of \(10\):

• Thousands column: \(10^3 = 1000\)
• Hundreds column: \(10^2 = 100\)
• Tens column: \(10^1 = 10\)
• Units column: \(10^0 = 1\)

Binary (Base-\(2\))

In binary, we only have two digits: \(0\) and \(1\). Each column moving to the left increases by a power of \(2\):

• \(2^7 = 128\)
• \(2^6 = 64\)
• \(2^5 = 32\)
• \(2^4 = 16\)
• \(2^3 = 8\)
• \(2^2 = 4\)
• \(2^1 = 2\)
• \(2^0 = 1\)

The rightmost bit is known as the Least Significant Bit (LSB) because it has the smallest place value (\(1\)). The leftmost bit is known as the Most Significant Bit (MSB) because it carries the largest place value.

Key Takeaway: Binary works exactly like decimal, but instead of multiplying by \(10\) as you move left, you multiply by \(2\).

2. Converting Between Binary and Denary

Method 1: Binary to Denary Conversion

To convert an \(8\)-bit unsigned binary number to denary, write the place values above each bit, then add together all the values where a \(1\) appears.

Worked Example: Convert the binary number \(10110100_2\) to denary.

1. Write down the place values: \(128, 64, 32, 16, 8, 4, 2, 1\)
2. Match them with the bits:
• \(128 \times 1 = 128\)
• \(64 \times 0 = 0\)
• \(32 \times 1 = 32\)
• \(16 \times 1 = 16\)
• \(8 \times 0 = 0\)
• \(4 \times 1 = 4\)
• \(2 \times 0 = 0\)
• \(1 \times 0 = 0\)
3. Add the values together: \(128 + 32 + 16 + 4 = 180_{10}\)

Method 2: Denary to Binary Conversion (Subtraction Method)

This is often the quickest method for written exams.

1. Write down the \(8\)-bit place values: \(128, 64, 32, 16, 8, 4, 2, 1\).
2. Compare your denary number to the leftmost place value (\(128\)).
3. If your number is equal to or larger than the place value, place a \(1\) in that column and subtract the value from your total.
4. If your number is smaller, place a \(0\) and move to the next column.
5. Repeat until you reach the end.

Worked Example: Convert \(77_{10}\) to an \(8\)-bit binary number.

• Is \(77 \ge 128\)? No \(\implies 0\)
• Is \(77 \ge 64\)? Yes \(\implies 1\) (Remainder: \(77 - 64 = 13\))
• Is \(13 \ge 32\)? No \(\implies 0\)
• Is \(13 \ge 16\)? No \(\implies 0\)
• Is \(13 \ge 8\)? Yes \(\implies 1\) (Remainder: \(13 - 8 = 5\))
• Is \(5 \ge 4\)? Yes \(\implies 1\) (Remainder: \(5 - 4 = 1\))
• Is \(1 \ge 2\)? No \(\implies 0\)
• Is \(1 \ge 1\)? Yes \(\implies 1\) (Remainder: \(1 - 1 = 0\))
Result: \(77_{10} = 01001101_2\)

Common Mistake to Avoid: Always ensure you output the requested number of bits. If the question asks for an \(8\)-bit representation, include leading zeros (e.g., write \(01001101\), not just \(1001101\)).

3. Binary Addition

Binary addition follows four simple rules:

• \(0 + 0 = 0\)
• \(0 + 1 = 1\)
• \(1 + 0 = 1\)
• \(1 + 1 = 0\) (carry \(1\) to the next column on the left)
• \(1 + 1 + 1 = 1\) (carry \(1\) to the next column on the left)

Worked Example: Add \(01011010_2\) (\(90_{10}\)) and \(00110110_2\) (\(54_{10}\)):

Line 1:   \(01011010\)
Line 2: + \(00110110\)
Carries:  \(1111\)
Result:  \(10010000_2\) (\(144_{10}\))

Overflow Errors

An overflow error occurs when the result of a binary addition requires more bits than the system has allocated to store it. For example, if adding two \(8\)-bit numbers produces a \(9\)-bit result, the extra most significant bit is discarded. This leads to an incorrect answer and can cause computer programs to crash or behave unpredictably.

Key Takeaway: When adding binary numbers, work from right to left, carrying forward any \(1\)s just like in standard columnar addition.

4. Logical Binary Shifts

A logical shift moves all the bits in a binary number a specified number of places to the left or to the right.

Logical Left Shift

• Every bit moves one position to the left.
• A \(0\) is inserted into the empty LSB position.
Effect: Multiplying the number by \(2\) for each shift position.
Example: A \(1\)-place left shift of \(00000101_2\) (\(5_{10}\)) produces \(00001010_2\) (\(10_{10}\)).

Logical Right Shift

• Every bit moves one position to the right.
• A \(0\) is inserted into the empty MSB position.
• The bit shifted out of the LSB is discarded.
Effect: Integer division by \(2\) (any fractional part is lost).
Example: A \(1\)-place right shift of \(00001100_2\) (\(12_{10}\)) produces \(00000110_2\) (\(6_{10}\)).

5. Representing Signed Integers

Computers need ways to represent both positive and negative numbers. Two common methods in digital technology are Sign and Magnitude and Two's Complement.

Method A: Sign and Magnitude

In this system, the Most Significant Bit (MSB) acts purely as a sign indicator:
• If the MSB is \(0\), the number is positive (\(+\)).
• If the MSB is \(1\), the number is negative (\(-\)).
• The remaining bits represent the magnitude (size) of the number.

Examples (\(8\)-bit):
• \(+25_{10} = \mathbf{0}0011001_2\)
• \(-25_{10} = \mathbf{1}0011001_2\)

Limitations of Sign and Magnitude:
1. It has two representations for zero: positive zero (\(00000000\)) and negative zero (\(10000000\)), which is inefficient and complicates arithmetic circuits.
2. Standard binary addition does not work directly on negative values represented in sign and magnitude.

Method B: Two's Complement

Two's complement is the standard method used by modern processors. In an \(8\)-bit two's complement system, the MSB has a negative place value of \(-128\), while all other place values remain positive (\(64, 32, 16, 8, 4, 2, 1\)).

How to convert a positive number into its negative Two's Complement:
1. Write the number in standard positive binary.
2. Invert all the bits (change all \(0\)s to \(1\)s and all \(1\)s to \(0\)s).
3. Add \(1\) to the inverted result.

Worked Example: Represent \(-35_{10}\) in \(8\)-bit Two's Complement.

1. Positive \(35_{10}\) in binary: \(00100011\)
2. Invert all bits: \(11011100\)
3. Add \(1\):
    \(11011100 + 1 = 11011101_2\)

Check using place values:
\(-128 + 64 + 0 + 16 + 8 + 4 + 0 + 1 = -128 + 93 = -35_{10}\). It matches!

Range of Values for \(n\) Bits

Unsigned \(n\)-bit integers: Range from \(0\) to \(2^n - 1\).
For \(8\) bits: \(0\) to \(255\).
Two's Complement \(n\)-bit signed integers: Range from \(-2^{n-1}\) to \(2^{n-1} - 1\).
For \(8\) bits: \(-128\) to \(+127\).

Quick Review and Summary

Denary: Base-\(10\) system using digits \(0\) to \(9\).
Binary: Base-\(2\) system using digits \(0\) and \(1\), matching the on/off states of computer transistors.
Binary Addition: Remember that \(1 + 1 = 10_2\) (carry \(1\)) and \(1 + 1 + 1 = 11_2\) (write \(1\), carry \(1\)).
Overflow: Occurs when the calculated value exceeds the available bit storage capacity.
Logical Shift: Left shift multiplies by \(2\); right shift divides by \(2\).
Two's Complement: The preferred method for signed integers because it allows normal addition circuits to perform subtraction and has only one representation for zero.