How Computer Stores Negetive Numbers (Using -11 as a Case Study)
The Computer as you know is a machine that understands **Binary** as it's primary language and also it stores data in Binary form, that represents numbers, alphabets, and symbols. This article is aimed at explaining how the computer stores **Negative Numbers**. To understand this phenomenon one must understand the following concepts.
Sign and Magnitude
Suppose that we are given a number say **11** , first we convert it to binary form
11/2= 5 r 1
5/2= 2 r 1
2/2= 1 r 0
1/2= 0 r 1
therefore 11 = 1011 in binary
**1** **0** **1** **1**
( sign) (magnitude)
So the first number in the Binary array is taken as the **Sign** , while the other following numbers are refered to as **Magnitude**
Worthy of note is that, the **Sign** bit when it is **1** is often refered to as a Negative while a **Sign** **0** is seen as a positive binary number.
**One's Complement**
This is a method of representing negative numbers by inverting all the bits of a positive number. For example , using the 5 bit binary system
11 in binary is 01011
and so this method says to invert all the bits to represent a positive number , so it will be
**01011** .= 11
**10100** = -11
**Two's Complement**
This is a ''step'' further from One's Component which gives a more accurate representation of negative numbers in binary.
using the 5 bit binary system
-11 = 10100 (*from One's Complement)*
then we add 1 that will give us the Two's complement
10100+ 1= 10101
therefore the Two's Complement for -11 = 10101
## Step by Step Conversion of -11 into 8 bit binary (using Two's Complement)
with 8 bit binary
128 = 0
64 = 0
32 = 0
16 = 0
8 = 1
4 = 0
2 = 1
1 = 1
therefore 11= 00001011
-11 = 11110100 *(One's Complement)*
convert to Two's Complement
11110100 + 1 = 11110101
therefore -11 = 11110101.
**Corresponding Hexadecimal value
**
given 11110101
(1 * 8) + (1 * 4) + (1 * 2) + (1* 1) = 15 = F
(0 * 8) + ( 1 * 4) + (2 * 0) + ( 1 * 1) = 5
**11110101=F5**