logo

Cambridge IGCSE Computer Science revision notes

Number systems Revision Notes

Cambridge IGCSE revision notes for Number systems.

At a glance

revision notes

Resource type

Topic

Number systems

CambridgeIGCSEComputer ScienceData representation

Complete revision guide 1 of 6

Binary Representation of Data in Computers

This note explains why computers use binary to represent data and how this representation is implemented using logic gates and registers. It covers the necessity of converting all data into binary form for processing, the role of binary states, and the hardware mechanisms involved in storing and manipulating binary data.

Syllabus source

Section 3, Topic 1.1, page 11, objective 1.1.1

Open source document ↗

What you should be able to do

  • ✓Understand why binary is used to represent data in computers.
  • ✓Explain how all types of data are converted into binary for processing.
  • ✓Describe the role of logic gates in manipulating binary data.
  • ✓Explain how registers store binary data temporarily during processing.
1

Why Computers Use Binary

Computers represent all data using the binary number system, which consists of only two digits: 0 and 1. This choice is fundamentally linked to the physical design of computer hardware. Electronic circuits inside computers have two stable states, often represented as off and on, or low voltage and high voltage. These two states naturally correspond to the binary digits 0 and 1.

Using binary simplifies the design of electronic components such as transistors and logic gates, which can reliably detect and switch between these two states. This reliability is crucial because it reduces errors caused by electrical noise or signal degradation, which would be more problematic if more states were used.

  • Binary uses only two digits: 0 and 1.
  • Electronic circuits have two stable states matching binary digits.
  • Binary representation reduces hardware complexity and error rates.
2

Converting All Data into Binary

Computers process various types of data including numbers, text, images, and sound. Regardless of the data type, it must be converted into binary form before processing. For example, text characters are converted into binary codes using standards like ASCII or Unicode, where each character corresponds to a unique binary number.

Images are represented as a grid of pixels, each pixel’s colour encoded in binary according to colour depth. Sound is sampled at regular intervals, with each sample converted into a binary number representing the amplitude at that moment.

This universal binary representation allows the computer’s central processing unit (CPU) to handle all data uniformly using the same basic operations on binary numbers.

  • Text, images, and sound are all converted into binary.
  • Text uses binary codes like ASCII or Unicode.
  • Images use binary to represent pixel colours.
  • Sound is sampled and converted into binary amplitude values.
3

Logic Gates and Binary Data Manipulation

Logic gates are the fundamental building blocks of digital circuits. They perform basic logical operations on binary inputs to produce a binary output. Common logic gates include AND, OR, NOT, NAND, NOR, XOR, and XNOR.

Each gate implements a simple Boolean function. For example, an AND gate outputs 1 only if both inputs are 1; otherwise, it outputs 0. By combining these gates, complex operations such as addition, subtraction, and data comparison can be performed on binary numbers.

Logic gates enable the CPU to execute instructions by manipulating binary data according to the program’s logic.

  • Logic gates perform operations on binary inputs.
  • Basic gates include AND, OR, NOT, NAND, NOR, XOR, XNOR.
  • Complex operations are built by combining gates.
  • Logic gates enable CPU instruction execution.
4

Registers: Temporary Storage of Binary Data

Registers are small, fast storage locations within the CPU that hold binary data temporarily during processing. They store values such as operands for arithmetic operations, memory addresses, or intermediate results.

Each register consists of a set of flip-flops or similar circuits that can hold a binary digit (bit). For example, an 8-bit register can store an 8-bit binary number, allowing the CPU to process data in fixed-size chunks.

Registers enable quick access to data without the delay of accessing main memory, improving processing speed.

  • Registers store binary data temporarily inside the CPU.
  • They consist of circuits that hold individual bits.
  • Registers have fixed sizes, e.g., 8-bit or 16-bit.
  • They provide fast access to data during processing.
5

Summary and Practical Example

In summary, computers use binary because it aligns with the physical properties of electronic circuits, allowing reliable and efficient data representation. All data types are converted into binary so that the CPU can process them uniformly using logic gates. Registers hold this binary data temporarily to facilitate fast computation.

For example, to represent the letter 'A' in binary, the ASCII code 65 is used. The decimal number 65 converts to binary as 01000001. This 8-bit binary number can be stored in a register and manipulated by logic gates during processing.

  • Binary matches electronic circuit states for reliability.
  • All data types are converted to binary for uniform processing.
  • Logic gates manipulate binary data to perform operations.
  • Registers temporarily hold binary data for quick access.
  • Example: 'A' in ASCII is 65 decimal, which is 01000001 binary.

At-a-glance summary

Comparison table

StepDetailExampleExam Use
Data conversionAll data types converted to binaryText 'A' → ASCII 65 → binary 01000001Explain why binary is universal for data
Logic gatesPerform Boolean operations on binary inputsAND gate: 1 AND 0 = 0Describe logic gate functions
RegistersStore binary data temporarily8-bit register holds 01000001State purpose of registers
Binary statesTwo stable states: 0 and 1Voltage low = 0, voltage high = 1Explain hardware basis for binary

Active recall

Quick check

1. Why do computers use binary instead of decimal to represent data?

Because electronic circuits have two stable states (on and off), binary digits 0 and 1 match these states, making data representation reliable and simple.

2. What must happen to all data before a computer can process it?

All data must be converted into binary form so the CPU can manipulate it using logic gates.

3. What is the role of logic gates in a computer?

Logic gates perform basic Boolean operations on binary inputs to process data and execute instructions.

4. Why are registers important in data processing?

Registers temporarily store binary data inside the CPU, allowing fast access and manipulation during processing.

Complete revision guide 2 of 6

Understanding and Converting Between Denary, Binary, and Hexadecimal Number Systems

This note explains the fundamental concepts of the denary (base 10), binary (base 2), and hexadecimal (base 16) number systems. It details methods to convert positive integers between these systems, including denary to binary, denary to hexadecimal, and hexadecimal to binary, with worked examples and practical tips for accuracy. The note emphasises the importance of these conversions in computer science and provides a comparison table to clarify each step.

Syllabus source

Section 3, Topic 1.1, page 11, objective 1.1.2

Open source document ↗

What you should be able to do

  • ✓Understand the structure and digit sets of denary, binary, and hexadecimal number systems.
  • ✓Perform conversions between positive denary and binary numbers.
  • ✓Perform conversions between positive denary and hexadecimal numbers.
  • ✓Perform conversions between positive hexadecimal and binary numbers.
  • ✓Apply conversion techniques accurately for numbers up to 16 bits in binary.
1

Number Systems: Bases and Digits

Number systems represent values using a set of digits and a base that determines place value. Denary (base 10) uses digits 0 to 9, with each digit's place value increasing by powers of 10 from right to left. Binary (base 2) uses only digits 0 and 1, with place values increasing by powers of 2. Hexadecimal (base 16) uses digits 0 to 9 and letters A to F (representing values 10 to 15), with place values increasing by powers of 16.

Understanding these bases is essential because computers operate using binary internally, but hexadecimal provides a more compact and human-friendly way to represent binary data. Denary is the familiar system used in everyday counting and calculations.

  • Denary digits: 0–9, base 10.
  • Binary digits: 0, 1, base 2.
  • Hexadecimal digits: 0–9, A–F, base 16.
2

Converting Positive Denary to Binary

To convert a positive denary integer to binary, repeatedly divide the number by 2, recording the remainder each time. The binary number is formed by reading the remainders from last to first.

For example, convert denary 13 to binary: divide 13 by 2: quotient 6, remainder 1; divide 6 by 2: quotient 3, remainder 0; divide 3 by 2: quotient 1, remainder 1; divide 1 by 2: quotient 0, remainder 1. Reading remainders bottom-up gives 1101.

This method works because each division extracts the least significant bit (LSB) of the binary representation. The process continues until the quotient is zero.

  • Divide by 2, note remainder.
  • Repeat with quotient until zero.
  • Binary is remainders read in reverse order.
3

Converting Positive Binary to Denary

To convert binary to denary, multiply each binary digit by its place value (a power of 2) and sum the results.

For example, binary 10110 represents: (1 × 2⁴) + (0 × 2³) + (1 × 2²) + (1 × 2¹) + (0 × 2⁰) = 16 + 0 + 4 + 2 + 0 = 22 denary.

This method uses the positional value of each bit, starting from the rightmost bit as 2⁰.

  • Multiply each bit by 2 to the power of its position index.
  • Sum all products for denary value.
4

Converting Positive Denary to Hexadecimal

Convert denary to hexadecimal by repeatedly dividing the number by 16 and recording the remainder each time. The hexadecimal number is formed by reading the remainders from last to first, using digits 0–9 and letters A–F for remainders 10–15.

For example, convert denary 254 to hexadecimal: divide 254 by 16: quotient 15, remainder 14 (E); divide 15 by 16: quotient 0, remainder 15 (F). Reading remainders bottom-up gives FE.

This method is analogous to denary-to-binary conversion but uses base 16 instead of 2.

  • Divide by 16, note remainder.
  • Repeat with quotient until zero.
  • Use digits 0–9 and letters A–F for remainders.
  • Read remainders in reverse order for hex number.
5

Converting Positive Hexadecimal to Denary

To convert hexadecimal to denary, multiply each digit by its place value (a power of 16) and sum the results.

For example, hexadecimal 3B7 represents: (3 × 16²) + (11 × 16¹) + (7 × 16⁰) = 768 + 176 + 7 = 951 denary.

Letters A–F correspond to decimal values 10–15. The rightmost digit is multiplied by 16⁰, the next by 16¹, and so on.

  • Convert letters A–F to decimal 10–15.
  • Multiply each digit by 16 to the power of its position index.
  • Sum all products for denary value.
6

Converting Between Hexadecimal and Binary

Each hexadecimal digit corresponds exactly to four binary digits (bits), because 16 = 2⁴. To convert hexadecimal to binary, replace each hex digit with its 4-bit binary equivalent.

For example, hex 2F converts to binary by converting 2 → 0010 and F → 1111, so 2F = 00101111 binary.

To convert binary to hexadecimal, split the binary number into groups of four bits starting from the right. Convert each group to its hexadecimal digit. Add leading zeros if necessary to complete the leftmost group of four bits.

  • Hex digit = 4 binary bits.
  • Hex to binary: replace each hex digit with 4-bit binary.
  • Binary to hex: group bits in fours, convert each group to hex digit.
  • Pad with leading zeros if needed.

At-a-glance summary

Comparison table

StepDenary to BinaryDenary to HexadecimalHexadecimal to Binary
Divide number by baseDivide by 2, record remainderDivide by 16, record remainderN/A
Repeat until quotient is zeroYesYesN/A
Read remaindersFrom last to first (bottom-up)From last to first (bottom-up)N/A
Direct digit mappingN/AN/AEach hex digit to 4-bit binary

Active recall

Quick check

1. What is the binary equivalent of denary 9?

Divide 9 by 2: 9 ÷ 2 = 4 remainder 1; 4 ÷ 2 = 2 remainder 0; 2 ÷ 2 = 1 remainder 0; 1 ÷ 2 = 0 remainder 1. Reading remainders bottom-up: 1001.

2. Convert hexadecimal 1A to denary.

1 × 16¹ + 10 × 16⁰ = 16 + 10 = 26.

3. Convert binary 110111 to hexadecimal.

Group bits in fours from right: 0011 0111. 0011 = 3, 0111 = 7, so hexadecimal is 37.

4. What digits are used in hexadecimal?

Digits 0–9 and letters A–F, where A=10, B=11,..., F=15.

Complete revision guide 3 of 6

Advantages of Using Hexadecimal for Data Representation

Hexadecimal numbering system offers a concise and human-friendly way to represent binary data, making it easier to read, write, and manage in various computer science applications such as memory addressing and colour coding.

Syllabus source

Section 3, Topic 1.1, page 11, objective 1.1.3

Open source document ↗

What you should be able to do

  • ✓Understand why hexadecimal is preferred over binary for human readability.
  • ✓Identify key areas in computer science where hexadecimal is applied.
  • ✓Explain how hexadecimal condenses binary data and improves clarity.
1

Introduction to Hexadecimal and Its Relation to Binary

Hexadecimal is a base-16 number system that uses sixteen distinct symbols: the digits 0 to 9 and the letters A to F, where A represents 10 and F represents 15 in decimal. Each hexadecimal digit corresponds exactly to four binary digits (bits). This direct relationship allows easy conversion between binary and hexadecimal.

For example, the binary number 11011110 can be split into two groups of four bits: 1101 and 1110. The first group, 1101, equals 13 in decimal, which is D in hexadecimal. The second group, 1110, equals 14 in decimal, which is E in hexadecimal. Thus, 11011110 in binary is DE in hexadecimal.

  • Hexadecimal is base 16, using digits 0–9 and letters A–F.
  • Each hex digit represents exactly 4 binary bits.
  • Conversion between binary and hex is straightforward by grouping bits in fours.
2

Why Hexadecimal Is More Efficient Than Binary for Humans

Binary numbers can become very long and difficult to read or write, especially when representing large values. Hexadecimal reduces the length of these numbers by a factor of four, making them more compact and easier to interpret.

For instance, an 8-bit binary number like 11110000 is eight digits long, but its hexadecimal equivalent is F0, only two digits. This compactness reduces errors when reading or writing numbers and simplifies debugging and programming tasks.

  • Hexadecimal shortens long binary sequences by grouping bits.
  • Improves readability and reduces human error.
  • Simplifies writing and interpreting binary data.
3

Applications of Hexadecimal in Computer Science

Hexadecimal is widely used in computer science wherever binary data needs to be represented in a human-friendly form. Key applications include:

Memory addressing: Memory locations are often shown in hexadecimal to compactly represent addresses that would be very long in binary.

Colour representation: In web design and graphics, colours are commonly specified using hexadecimal codes, such as #FF5733, where each pair of hex digits represents red, green, and blue intensity levels respectively, each ranging from 00 to FF (0 to 255 decimal). This makes colour codes concise and easy to manipulate compared to binary or decimal values.

  • Memory addresses are displayed in hexadecimal for compactness.
  • Hexadecimal codes represent colours in graphics and web design.
  • Programming languages use hex to represent binary data efficiently.
4

Converting Between Binary and Hexadecimal: A Practical Example

To convert a binary number to hexadecimal, split the binary number into groups of four bits starting from the right. Convert each group to its hexadecimal equivalent.

Example: Convert binary 101101111001 to hexadecimal.

Step 1: Split into groups of four bits: 1011 0111 1001. Step 2: Convert each group: 1011 = 11 decimal = B hex; 0111 = 7 decimal = 7 hex; 1001 = 9 decimal = 9 hex. Step 3: Combine: B79 hex. Therefore, 101101111001 binary equals B79 hexadecimal.

  • Group binary digits in fours from right to left.
  • Convert each group to decimal, then to hex digit.
  • Combine hex digits for the final hexadecimal number.
5

Summary of Hexadecimal Advantages and Usage

Hexadecimal provides a concise, readable way to represent binary data, reducing the length of binary strings by a factor of four. This makes it easier for humans to read, write, and debug data in computing contexts.

Its applications in memory addressing, colour coding, and programming highlight its importance in computer science. Understanding hexadecimal and its relationship to binary is essential for efficient data representation and manipulation.

  • Hexadecimal condenses binary data for human use.
  • Widely applied in memory addresses and colour codes.
  • Essential for programmers and computer scientists to interpret binary data efficiently.

At-a-glance summary

Comparison table

StepDetailExampleExam Use
Grouping binary digitsSplit binary into groups of 4 bits from rightBinary 11011110 → 1101 1110Show clear grouping when converting
Converting groupsConvert each 4-bit group to decimal then hex1101 → 13 decimal → D hexWrite hex digits accurately
Combining digitsJoin hex digits to form final number11011110 binary → DE hexPresent final answer clearly
Reading hexUnderstand hex digits represent 4 bitsHex F0 = 11110000 binaryExplain hex shortens binary length

Active recall

Quick check

1. How many binary bits does one hexadecimal digit represent?

One hexadecimal digit represents exactly 4 binary bits.

2. Why is hexadecimal preferred over binary for human reading?

Because hexadecimal condenses long binary sequences into shorter, easier-to-read digits, reducing errors and simplifying interpretation.

3. Give one example of where hexadecimal is used in computer science.

Hexadecimal is used to represent memory addresses compactly.

4. Convert binary 11110000 to hexadecimal.

11110000 binary equals F0 in hexadecimal.

Complete revision guide 4 of 6

Binary Addition and Overflow in 8-bit Numbers

This note explains how to add two positive 8-bit binary numbers, the concept of overflow in binary addition, and why overflow occurs when the result exceeds the storage capacity of an 8-bit register.

Syllabus source

Section 3, Topic 1.1, page 11, objective 1.1.4

Open source document ↗

What you should be able to do

  • ✓Perform addition of two positive 8-bit binary numbers accurately.
  • ✓Understand the maximum value representable by an 8-bit binary number.
  • ✓Explain the concept of overflow in binary addition and identify its causes.
  • ✓Recognise the implications of overflow errors in computer systems.
1

Understanding 8-bit Binary Numbers

An 8-bit binary number consists of 8 binary digits (bits), each bit representing a power of 2, starting from 2^0 on the right to 2^7 on the left. Because each bit can be either 0 or 1, the smallest value is 00000000 (decimal 0) and the largest is 11111111 (decimal 255).

The maximum decimal value for an 8-bit unsigned binary number is calculated as:

(2^7) + (2^6) + (2^5) + (2^4) + (2^3) + (2^2) + (2^1) + (2^0) = 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255.

  • 8 bits represent values from 0 to 255 inclusive.
  • Each bit corresponds to a power of 2, from 2^0 to 2^7.
  • The largest 8-bit number is 11111111 in binary, equal to 255 in decimal.
2

Adding Two Positive 8-bit Binary Numbers

Binary addition follows rules similar to decimal addition but uses base 2. The rules for adding two bits are:

0 + 0 = 0 (sum 0, carry 0) 0 + 1 = 1 (sum 1, carry 0) 1 + 0 = 1 (sum 1, carry 0) 1 + 1 = 0 (sum 0, carry 1) — because 1 + 1 in binary equals 10 (2 in decimal).

When adding two 8-bit numbers, start from the least significant bit (rightmost) and move left, adding each pair of bits along with any carry from the previous addition. The carry is added to the next bit pair.

  • Add bits from right to left, including any carry.
  • If sum of bits is 2 (binary 10), write 0 and carry 1 to next bit.
  • Continue until all bits and carry are processed.
  • If a carry remains after the leftmost bit, it indicates overflow.
3

Worked Example: Adding 8-bit Binary Numbers

Add the two 8-bit binary numbers: 00110110 (decimal 54) and 01001101 (decimal 77).

Step 1: Write the numbers aligned by bit position:

00110110 (54) + 01001101 (77) ----------------- Step 2: Add bit by bit from right to left, including carry: Bit 0: 0 + 1 = 1, carry 0 Bit 1: 1 + 0 = 1, carry 0 Bit 2: 1 + 1 = 0, carry 1 Bit 3: 0 + 1 + carry 1 = 0, carry 1 Bit 4: 1 + 0 + carry 1 = 0, carry 1 Bit 5: 1 + 0 + carry 1 = 0, carry 1 Bit 6: 0 + 1 + carry 1 = 0, carry 1 Bit 7: 0 + 0 + carry 1 = 1, carry 0 Step 3: Write the result bits from left to right: 10000011 Step 4: Convert result to decimal: 1×128 + 0 + 0 + 0 + 0 + 0 + 1×2 + 1×1 = 128 + 0 + 0 + 0 + 0 + 0 + 2 + 1 = 131 Step 5: Check decimal sum: 54 + 77 = 131, which matches the binary result. No overflow occurred because the result fits within 8 bits.

  • Add bits right to left, including carry.
  • Result is 10000011 (binary) = 131 (decimal).
  • Sum is within 0–255, so no overflow.
4

Concept of Overflow in Binary Addition

Overflow happens when the sum of two binary numbers exceeds the maximum value that can be stored in the given number of bits. For an 8-bit register, this maximum is 255. If the result is greater than 255, the register cannot represent the correct value, causing an overflow error.

Overflow is detected if there is a carry out of the most significant bit (leftmost bit) after addition. This carry cannot be stored in the 8-bit register, so the result wraps around, leading to an incorrect value.

For example, adding 11111111 (255) and 00000001 (1) results in 1 00000000 (binary 9 bits), but only the lower 8 bits (00000000) are stored, which is 0 in decimal — an incorrect result due to overflow.

  • Overflow occurs if sum > 255 for 8-bit numbers.
  • Carry out of the leftmost bit indicates overflow.
  • Overflow causes incorrect results due to limited register size.
5

Implications and Handling of Overflow

Overflow can cause serious errors in computations if not detected or handled properly. In computer systems, overflow detection is important to ensure data integrity.

Some processors have flags (overflow or carry flags) that indicate when overflow occurs, allowing software to respond appropriately, such as by raising an error or using larger registers.

Understanding overflow helps in designing algorithms and systems that avoid exceeding data limits or that use larger bit-widths when necessary.

  • Overflow detection is critical for reliable computing.
  • Processors use flags to signal overflow.
  • Programmers must consider overflow when working with fixed-size registers.

At-a-glance summary

Comparison table

StepDetailExampleExam Use
Identify bit positionsNumber bits from right (0) to left (7)Bit 0 is least significant bitAlways start addition from bit 0
Add bits with carryAdd corresponding bits plus carry from previous1 + 1 + carry 0 = sum 0, carry 1Show carry clearly in working
Check for overflowLook for carry out of bit 7Carry out = 1 means overflowState overflow if carry out present
Convert resultConvert final binary sum to decimal10000011 binary = 131 decimalWrite final answer in decimal

Active recall

Quick check

1. What is the maximum decimal value that can be represented by an 8-bit binary number?

255, because 8 bits can represent values from 0 to 2^8 - 1 = 255.

2. What does a carry out of the most significant bit indicate in 8-bit binary addition?

It indicates an overflow error, meaning the result cannot be represented within 8 bits.

3. Add 00011001 (25) and 00100111 (39) in binary and state if overflow occurs.

Sum is 01011100 (decimal 64). No overflow occurs because the result is less than 255.

4. Why is overflow a problem in computer systems?

Because it causes incorrect results when the sum exceeds the register size, leading to data errors or system faults.

Complete revision guide 5 of 6

Logical Binary Shifts on 8-bit Positive Binary Numbers

This note explains how to perform logical left and right shifts on positive 8-bit binary numbers, detailing the process, effects on the number's value, and the consequences of bit loss during shifting.

Syllabus source

Section 3, Topic 1.1, page 12, objective 1.1.5

Open source document ↗

What you should be able to do

  • ✓Understand the procedure for logical left and right shifts on 8-bit binary numbers.
  • ✓Recognise how bits shifted out are lost and zeros are introduced at the opposite end.
  • ✓Explain how left shifts multiply and right shifts divide the integer value by powers of two.
  • ✓Appreciate the impact of losing significant bits during shifting operations.
  • ✓Perform multiple logical shifts and predict the resulting binary and decimal values.
1

Introduction to Logical Binary Shifts

Logical binary shifts move all bits in a binary number either to the left or to the right by a specified number of positions. This operation is performed on fixed-length binary numbers, such as 8-bit registers, which can represent integers from 0 to 255 when unsigned.

In a logical left shift, bits move towards the more significant positions (left), and zeros fill the least significant bits (right). Conversely, a logical right shift moves bits towards the less significant positions (right), and zeros fill the most significant bits (left).

Bits that move beyond the register boundary are discarded and lost permanently. This loss can affect the numerical value represented by the binary number.

  • Shifting moves bits left or right within a fixed-length register.
  • Zeros fill the vacant bit positions opposite to the shift direction.
  • Bits shifted out of the register are lost and cannot be recovered.
2

Logical Left Shift: Multiplying by Powers of Two

Each logical left shift on a positive binary number effectively multiplies the number by 2, provided no significant bits are lost during the shift.

For example, consider the 8-bit binary number 00011010, which equals 26 in decimal.

Performing one logical left shift: shift all bits one place left, discard the leftmost bit if it moves out, and insert a zero at the rightmost bit.

  • Original: 00011010 (decimal 26)
  • After 1 left shift: 00110100 (decimal 52)
  • Calculation: 26 × 2 = 52
  • If multiple left shifts are performed, multiply by 2 for each shift (e.g., two shifts multiply by 4).
3

Logical Right Shift: Dividing by Powers of Two

Each logical right shift divides the number by 2, discarding any remainder, as bits shifted out on the right are lost and zeros are inserted on the left.

For example, take the 8-bit binary number 00110100 (decimal 52).

Performing one logical right shift moves bits one place right, inserts zero on the left, and discards the rightmost bit.

  • Original: 00110100 (decimal 52)
  • After 1 right shift: 00011010 (decimal 26)
  • Calculation: 52 ÷ 2 = 26 (integer division)
  • Multiple right shifts divide by 2 for each shift, discarding remainders (e.g., two shifts divide by 4).
4

Impact of Bit Loss and Register Limits

When bits are shifted out of the 8-bit register, they are lost permanently. This can cause significant changes in the number's value, especially if the lost bits contain important information.

For example, shifting 11110000 (decimal 240) left by one bit results in 11100000 (decimal 224) after discarding the leftmost bit. The expected multiplication by 2 would be 480, which cannot be represented in 8 bits, so overflow occurs and the value wraps around incorrectly.

Similarly, right shifts discard the least significant bits, which means fractional parts are lost during division, resulting in integer division with truncation.

  • Loss of bits can cause overflow or loss of precision.
  • 8-bit registers can only represent values 0 to 255; exceeding this causes incorrect results.
  • Right shifts perform integer division, losing fractional parts.
  • Always consider register size limits when shifting.
5

Performing Multiple Logical Shifts

Logical shifts can be performed multiple times in succession. Each shift multiplies or divides the number by 2, so multiple shifts multiply or divide by powers of two.

For example, shifting 00000011 (decimal 3) left by 3 bits:

After 1 shift: 00000110 (6) = 3 × 2¹, no bit loss; 6 ≤ 255, valid result. After 2 shifts: 00001100 (12) = 3 × 2², still valid. After 3 shifts: 00011000 (24) = 3 × 2³, still valid.

  • Multiple shifts multiply/divide by 2ⁿ, where n is the number of shifts.
  • Check for bit loss or overflow after each shift.
  • Use binary arithmetic to verify results.
  • Example: shifting 00000011 left 3 times results in 00011000 (decimal 24).

At-a-glance summary

Comparison table

StepDetailExampleExam Use
Logical Left ShiftMove bits left, insert 0 on right, lose leftmost bits00011010 → 00110100 (26 → 52)Show multiplication by 2 per shift
Logical Right ShiftMove bits right, insert 0 on left, lose rightmost bits00110100 → 00011010 (52 → 26)Show integer division by 2 per shift
Bit LossDiscard bits shifted out of 8-bit register11110000 left shift loses '1' bit, value changesExplain overflow or loss of significant bits
Multiple ShiftsRepeat shifting n times, multiply/divide by 2ⁿ00000011 left shift 3 times → 00011000 (3 × 8 = 24)Calculate final value after multiple shifts

Active recall

Quick check

1. What happens to bits shifted out during a logical shift?

They are lost permanently and cannot be recovered.

2. How does a single logical left shift affect the decimal value of a positive 8-bit binary number?

It multiplies the value by 2, provided no significant bits are lost.

3. What value is inserted at the opposite end during a logical right shift?

Zero is inserted at the leftmost bit position.

4. If you perform three logical right shifts on 00101000 (decimal 40), what is the resulting decimal value?

After three right shifts, the value is 5 because 40 ÷ 2³ = 40 ÷ 8 = 5.

Complete revision guide 6 of 6

Two's Complement Representation of 8-bit Signed Integers

This note explains how the two's complement system represents both positive and negative integers using 8-bit binary numbers. It covers conversion methods between denary and two's complement binary, the range of representable values, and the reasoning behind this system's design for efficient arithmetic in computers.

Syllabus source

Section 3, Topic 1.1, page 12, objective 1.1.6

Open source document ↗

What you should be able to do

  • ✓Understand the concept of two's complement for signed integer representation.
  • ✓Convert positive and negative denary integers to 8-bit two's complement binary.
  • ✓Convert 8-bit two's complement binary numbers back to denary integers.
  • ✓Recognise the range of values representable with 8-bit two's complement.
  • ✓Explain why two's complement simplifies binary arithmetic in computers.
1

Introduction to Two's Complement

Computers represent numbers in binary, but to handle both positive and negative integers, a special system is needed. Two's complement is the most common method for representing signed integers in binary form. It allows a single binary system to encode positive and negative numbers, enabling straightforward arithmetic operations such as addition and subtraction without separate logic for signs.

In an 8-bit system, each number is stored in a sequence of 8 bits (binary digits), where the leftmost bit (most significant bit) indicates the sign: 0 for positive, 1 for negative. Two's complement encoding ensures that arithmetic operations work correctly across positive and negative values.

  • Two's complement uses 8 bits to represent integers.
  • The most significant bit (MSB) is the sign bit: 0 means positive, 1 means negative.
  • It allows addition and subtraction without separate sign handling.
2

Range of 8-bit Two's Complement Numbers

With 8 bits, two's complement can represent integers from -128 to +127. This range arises because one bit is reserved for the sign, and the remaining bits represent the magnitude.

The smallest number is -128, represented as 10000000 in binary.

The largest number is +127, represented as 01111111 in binary.

  • Range: -128 to +127 for 8-bit two's complement.
  • Negative numbers have MSB = 1; positive numbers have MSB = 0.
  • Zero is represented as 00000000.
3

Converting Positive Denary to Two's Complement Binary

For positive integers (including zero), conversion to two's complement is straightforward: convert the number to binary normally and ensure it fits in 8 bits by adding leading zeros if necessary.

Example: Convert +18 to 8-bit two's complement binary.

Step 1: Convert 18 to binary: 10010 (which is 5 bits). Step 2: Add leading zeros to make 8 bits: 00010010. Result: 00010010 represents +18 in two's complement.

  • Positive numbers are represented as standard binary.
  • Pad with leading zeros to fill 8 bits.
  • Example: +18 → 00010010.
4

Converting Negative Denary to Two's Complement Binary

To convert a negative integer to two's complement:

1. Find the binary representation of its absolute value in 8 bits.

2. Invert all bits (change 0 to 1 and 1 to 0). 3. Add 1 to the inverted binary number. This process produces the two's complement representation of the negative number, allowing computers to perform arithmetic correctly using the same addition circuitry as for positive numbers. Example: Convert -18 to 8-bit two's complement binary. Step 1: Absolute value of -18 is 18 → 00010010. Step 2: Invert bits: 11101101. Step 3: Add 1: 11101101 + 1 = 11101110. Result: 11101110 represents -18 in two's complement.

  • Invert bits of absolute value's binary.
  • Add 1 to the inverted bits.
  • Example: -18 → 11101110.
5

Converting Two's Complement Binary to Denary

To convert an 8-bit two's complement binary number back to denary:

If the MSB is 0, convert the binary directly to denary as a positive number.

If the MSB is 1, the number is negative: 1. Invert all bits. 2. Add 1 to the inverted bits. 3. Convert the result to denary and add a negative sign. Example: Convert 11101110 to denary. MSB is 1, so number is negative. Invert bits: 00010001. Add 1: 00010001 + 1 = 00010010. Convert to denary: 18. Result: -18.

  • If MSB=0, convert directly to positive denary.
  • If MSB=1, invert bits, add 1, convert to denary, then negate.
  • Example: 11101110 → -18.
6

Why Two's Complement is Used in Computers

Two's complement simplifies hardware design because addition and subtraction can be performed using the same binary addition circuits for both positive and negative numbers. There is no need for separate subtraction logic or sign handling.

It also avoids the problem of having two representations for zero, which occurs in other signed number systems like sign-magnitude.

This efficiency makes two's complement the standard method for signed integer representation in almost all modern computer systems.

  • Enables uniform addition and subtraction circuitry.
  • Eliminates dual zero representations.
  • Simplifies computer arithmetic and logic design.

At-a-glance summary

Comparison table

StepDetailExampleExam Use
Convert positive denary to two's complementConvert denary to binary and pad to 8 bits+18 → 00010010Show binary with leading zeros for positive numbers
Convert negative denary to two's complementInvert bits of absolute value and add 1-18 → 11101110Explain inversion and addition clearly
Convert two's complement to denary (MSB=0)Direct binary to denary conversion00010010 → +18Identify MSB and convert directly if 0
Convert two's complement to denary (MSB=1)Invert bits, add 1, convert, then negate11101110 → -18Show all steps for negative binary numbers
Range of 8-bit two's complementFrom -128 to +12710000000 → -128, 01111111 → +127State range and sign bit meaning

Active recall

Quick check

1. What is the two's complement 8-bit binary representation of +45?

Convert 45 to binary: 101101. Pad to 8 bits: 00101101.

2. How do you convert -60 to two's complement binary?

Convert 60 to binary: 00111100. Invert bits: 11000011. Add 1: 11000100.

3. What is the denary value of 11111010 in two's complement?

MSB is 1, so negative. Invert bits: 00000101. Add 1: 00000110 (6). Result: -6.

4. What is the range of numbers representable by 8-bit two's complement?

From -128 (10000000) to +127 (01111111).

5. Why is two's complement preferred for signed integer representation?

Because it allows addition and subtraction using the same binary addition circuits and avoids two zeros.

Related topics

Study nearby topics next

Revision hubs

Keep studying from the right hub