Signed Binary Numbers

What are signed binary numbers?

  • A binary number can be signed or unsigned:

    • Unsigned - used to represent positive binary numbers
    • Signed - used to represent both positive and negative binary numbers
  • We can use signed binary numbers to represent negative numbers using methods such as:

    • Sign & magnitude
    • Two’s complement
  • Both of these methods use the Most Significant Bit (MSB) to represent whether the number is negative or positive:

    • If the MSB is 0, the number is positive
    • If the MSB is 1, the number is negative

Sign & Magnitude

  • Sign & magnitude binary numbers contain a:
    • Sign - This is when the MSB is used to represent whether the number is negative (1) or positive (0)
    • Magnitude - This is used to describe the rest of the bits after the MSB

sign-and-magnitude Representing negative binary numbers using sign & magnitude

Binary to denary example

  • To convert a sign & magnitude binary number to denary, you need to:
    • Convert the number as normal from binary to denary (as described in Positive Binary number: Binary to Denary)
    • Apply the MSB at the end of the calculation
      • If the MSB is 1, the number is negative
      • If the MSB is 0, the number is positive

msb-binary-to-decimal Converting sign & magnitude binary numbers to denary

Denary to binary example

  • To convert a denary number to a sign & magnitude binary number, you need to:
    • Identify whether the number is positive or negative
    • Convert the number to binary as normal (as described in Positive Binary Numbers: Denary to Binary)
    • If the number is negative, change the MSB to 1
MSB6432168421
11000111
  • 64 + 4 + 2 + 1 = 71
  • Apply a sign of 1 to make -71
  • Therefore the denary number -71 in binary is 11000111

A consequence of using a sign bit

  • The MSB purpose changes from representing a value to representing positive or negative
  • Losing the MSB halves the maximum size of the number that can be stored
  • However, as a benefit it makes it possible to represent negative numbers

sign-magnitude-number-system Sign & magnitude number system

Worked Example

Convert the 8-bit sign and magnitude binary number 10001011 to denary.

How to answer this question:

  • Identify the sign bit: The MSB is 1, so the number is negative
  • Isolate the magnitude: We are left with 0001011 by removing the sign bit
  • Convert to denary: The binary number 0001011 converts to 11 in denary
  • Apply the sign: The MSB was 1, so the number is -11 in denary

Answer that gets full marks

10001011 converts to -11 in denary

Two’s Complement

  • Two’s complement is a different method for representing negative binary numbers
  • Calculations on two’s complement numbers are less computationally intensive

Method

  1. Start with the absolute value of the number, in this case 12
  2. Invert the bits so that all of the 1’s become 0’s and all of the 0’s become 1’s
  3. Add 1

Diagram showing conversion of denary 12 to binary, inversion, adding one to form two's complement, resulting in negative offset -12 in binary. Representing two’s complement binary numbers

  • The purpose of the MSB has changed; it now represents the negative starting point of the number, and the rest of the bits are used to count upwards from that number
  • Using the binary number from the image above:
    • Begin counting at -16
    • Add 4 to make -12
  • Two’s complement has a similar consequence to sign and magnitude as the maximum value of an 8-bit value is halved

Denary to binary example

  • To convert the denary number -24 to a two’s complement binary number, you need to:
    • Convert the number to binary
-1286432168421
00011000
  • Invert the bits
-1286432168421
11100111
  • Add 1 to the number
-1286432168421
11101000