Introduction: The Need for Negative Numbers

In our previous lessons, we learned how to build circuits that add positive numbers together. However, a computer that can only count upwards is very limited. To perform subtraction or represent values like a bank balance below zero, we need a way to show negative numbers.

In the physical world, we simply put a minus sign (-) in front of a number. In a digital circuit, we only have wires that are either on (1) or off (0). We do not have a third option for a minus sign. To solve this, we must decide on a rule for how to use our bits to represent a negative value.

The most common way to do this is to look at the leftmost bit in a sequence. This is often called the Sign Bit. If we are using 4-bit numbers, we use that first slot to tell us if the number is positive or negative, while the remaining bits tell us the value.

Sign/Magnitude: Reserving the First Bit
One’s Complement: The Bit-Flipping Trick
Two’s Complement: The Standard for Modern Math
Summary and Preparing for Practice

You have now seen the three main ways to represent negative numbers in binary:

  • Sign/Magnitude: Uses the first bit as a +/- switch (simple but creates math errors).
  • One's Complement: Flips all bits (better for math but has two zeros).
  • Two's Complement: Flips all bits and adds one (the industry-standard).

Remember the Negative Identification Rule: In all these systems, if the leftmost bit is a 1, the number is negative. If it is a 0, it is positive.

In the upcoming practice exercises, you will get hands-on experience in the CodeSignal IDE. You will build circuits using NOT gates to flip bits and Adders to complete the Two's Complement process. This will help you see exactly how a computer turns a positive number into a negative one!

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal