Revise Computingrevisecomputing.co.uk
Free student revisionSee questionsFor schoolsSchool enquiry
Free revisionSee questionsFor schoolsSchool enquiry
Knowledge/A Level/H446/01 Computer systems/Data Types/Sign and magnitude and two's complement…

Sign and magnitude and two's complement to represent negative numbers

Use of sign and magnitude and two’s complement to represent negative numbers in binary

1.4.1 Data Types

Data Types — Note 3 of 10

Candidates should know how to store negative numbers using Sign and Magnitude and two’s complement. Candidates should be able to convert denary numbers to sign and magnitude, and two’s complement – and vice-versa

What you need to know

Negative integers can be represented in binary using sign and magnitude or two's complement. Two's complement is used by computers because binary addition works correctly with it and there is only one representation of zero.

What to know

Key terms

Exam tipCommon mistake

Sign and magnitude

The most significant bit (MSB) is the sign (0 = positive, 1 = negative) and the remaining bits hold the size of the number.

  • -45 in 8 bits = 10101101. Range in 8 bits: -127 to +127.
  • Sign and magnitude drawbacks: two representations of zero (00000000 and 10000000), and normal binary addition gives wrong answers.
Two's complement

The MSB has a NEGATIVE place value. In 8 bits the place values are -128 64 32 16 8 4 2 1.

  • To make a number negative in two's complement: write the positive binary, flip every bit, then add 1. (Or: from the right, copy up to and including the first 1, then flip the remaining bits.)
  • Two's complement: -45 = 11010011 (-128 + 64 + 16 + 2 + 1). Range in 8 bits: -128 to +127.
  • Two's complement benefits: one representation of zero; addition and subtraction work with ordinary binary addition.
  • Exam tip: To convert two's complement to denary, add the place values using -128 for the MSB.

Exam technique

  • Mistake:Forgetting to add 1 after flipping the bits.

Code examples

Converting -45 to 8-bit two's complement
text
+45           0 0 1 0 1 1 0 1
Flip bits     1 1 0 1 0 0 1 0
Add 1       + 0 0 0 0 0 0 0 1
-45           1 1 0 1 0 0 1 1

Check: -128 + 64 + 16 + 2 + 1 = -45
← Previous noteRepresent positive integers in binary1.4.1 Data TypesNext note →Addition and subtraction of binary integers1.4.1 Data Types

Back to Data Types

Data Types

Note 3 of 10

  1. 1Primitive data types: integer, real/floating point, character, string and Boolean
  2. 2Represent positive integers in binary
  3. 3Sign and magnitude and two's complement to represent negative numbers
  4. 4Addition and subtraction of binary integers
  5. 5Represent positive integers in hexadecimal
  6. 6Convert positive integers between binary, hexadecimal and denary
  7. 7Representation and normalisation of floating point numbers in binary
  8. 8Floating point arithmetic: addition and subtraction
  9. 9Bitwise manipulation and masks: shifts, combining with AND, OR and XOR
  10. 10How character sets (ASCII and UNICODE) are used to represent text
Topic overview