---
# System prepended metadata

title: How Computers Store Negative Numbers

---

# How Computers Store Negative Numbers

Typically we all know that the only thing computers or a computer understands are zeros and ones (0s & 1s) and whatever data types that are being stored, it converts them to zeros and ones for understanding and storage. Using ASCII values and tables we get to see how various characters of various data types are represented for the purpose of understanding and information interchange.

Looking at number data types you would see that only the positive or whole numbers have a binary representations and which equivalently tells us or lets us know how they are stored and you might ask yourself, "how then are negative numbers stored on the computer?"

In modern computers, negative numbers are typically stored using a binary representation called two's complement.

The two's complement representation allows for the storage of both positive and negative integers in a fixed-width binary format. The most significant bit (MSB) is used to represent the sign of the number, where 0 represents a positive number, and 1 represents a negative number. To understand the above statements fully, we will dive a little deep into inmportant concepts that will give clearer understanding the explantion.These concepts are signed magnitude and one's complement.

SIGNED MAGNITUDE:

In mathematics, positive numbers (including zero) are represented as unsigned numbers. That is we do not put the +ve sign in front of them to show that they are positive numbers. But when dealing with negative numbers we do use a -ve sign in front of the number to show that the number is negative in value and different from a positive unsigned value, and the same is true with signed binary numbers. So basically, Sign & magnitude notation is the simplest and one of the most obvious methods of encoding positive and negative numbers. Assign the leftmost (most significant) bit to be the sign bit. If the sign bit is 0, this means the number is positive. If the sign bit is 1, then the number is negative. The remaining bits are used to represent the magnitude of the binary number in the unsigned binary notation. 


ONE'S COMPLEMENT:

One's complement is the original system for representing integers (both positive and negative) in binary; this method is done by inverting or flipping the given numbers. To get 1’s complement of a binary number, simply invert the given number. For example, 1’s complement of binary number 110010 is 001101.

TWO'S COMPLEMENT:

Two's complement is a method of representing signed (positive, negative, or zero) integers in binary. It's a way to represent both positive and negative numbers in a binary system so that common math problems, like subtraction, are easily implemented. To get 2’s complement of binary number is 1’s complement of given number plus 1 to the least significant bit (LSB). For example 2’s complement of binary number 10010 is (01101) + 1 = 01110.

From the explantions of the concepts I did mention, you can see the procedural steps the computer uses to store up negative. We will be putting this into practice using the integer "-11" as our case study.

To store up this integer we will go through the following steps;

1. We will first convert the magnitude, that is the plain 11 or +11 into 8-bit binary form

         11 to 8-bit binary = 0000 1011
         
         to confirm you can convert the binary back to decimal by;
         
          0*2⁷ + 0*2⁶ + 0*2⁵ + 0*2⁴ + 1*2³ + 0*2² + 1*2¹ + 1*2⁰ = 8 + 2 + 1 = 11
         
         
2.Secondaly we will now get the one's complement of the binary number by inverting each bit of 0000 1011

	0000 1011 inverted becomes 1111 0100
	
	
3. Finally we now get the two's complement by adding 1 to the one's complement.


	 
      `1111 0100`
	  
	  `+       1`
	  `-----------`
	  
  `1111 0101`


  	  
  	  
So the -11 now becomes stored in the computer in binary as, 1111 0101₂.


Now to get the hexadecimal value of the two's complement, we will split the 8-bit binary number into two 4-bit nybbles and

using the hexadecimal notation 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A-10, B-11, C-12, D-13, E-14, F-15 we look for each individual hexadecimal value.

`1*2³ + 1*2² + 1*2¹ + 1*2⁰ = 8 + 4 + 2 + 1 = 15 → F in hex`

`0*2³ + 1*2² + 0*2¹ + 1*2⁰ = 0 + 4 + 0 + 1 = 5 → 5 in hex`


	1111  0101
  	F     5

    OxF5 (with the Ox denoting it is a hexadecimal value)


CONCLUSION

You probably noticed that the storage of negative integers is a process of steps linked between signed & magnitude, one's complement and two's complement representation of binary numbers. It is also important to know that there are also other representations like floating-point numbers and more research would be of benefit to study.
