To two's complement

Convert denary to signed binary (Two's complement): 0

Two's complement is used to represent signed (positive and negative) numbers in binary.

  • Positive numbers (0 to 127): Convert to binary normally, pad to 8 bits
  • Negative numbers (-1 to -128): Convert absolute value to binary, flip all bits, add 1

Example: Convert -6 to two's complement

6 in binary: 00000110
Flip bits:   11111001
Add 1:       11111010

How to convert from denary to two's complement binary:

  1. For positive numbers (0 to 127):
    • Convert the number to binary as normal
    • Pad with leading zeros to make it 8 bits
    • The most significant bit (MSB) will be 0, indicating a positive number
  2. For negative numbers (-1 to -128):
    • Take the absolute value of the number
    • Convert to binary and pad to 8 bits
    • Flip all the bits (0 becomes 1, 1 becomes 0)
    • Add 1 to the result
    • The MSB will be 1, indicating a negative number

Example 1: Convert 23 to two's complement

  • 23 is positive, so convert normally: 23 = 101112
  • Pad to 8 bits: 000101112
  • MSB is 0, indicating positive

Example 2: Convert -6 to two's complement

  • Take absolute value: 6
  • Convert to binary: 6 = 1102
  • Pad to 8 bits: 000001102
  • Flip all bits: 111110012
  • Add 1: 111110102
  • MSB is 1, indicating negative

Range: 8-bit two's complement can represent numbers from -128 to +127

References:

  • BBC Bitesize GCSE: Edexcel
  • Wikibooks Computer Science A level (two's complement): AQA OCR