# How computer store negetive numbers (using -11 as case study) ## introduction the computer are not just storing the value of numbers but also their associated sig, whether it is positive or negative. the sign help to determine the values of the numbers. take a look at the number line, these numbers could be to the left or to thr right of the number'0'. if the direction is to left, the number have negative sign attached to it and if it is to the right, it have a positive sign. The computer should be capable of representing these values. that's why we are having: 1. sign and magnitude 2. 1's complement 3. 2's complement ## sign and magnitude In the sign and magnitude representation the left most bit or most significant bit is used to indicate the sign while the remaining bits represent the magnitude value of the numbers. if the most significant bit is 0 it means the number is positive but if it's 1 it means the number is negative ## 1's complement To get the negative number representation in 1's complement, every digit of of the positive number is flipped to get the 1's complement of the number. the 1 become 0 and 0 become 1 ## 2's complement For the 2's complement, to get the negative number, 1 is added to the 1's complement the number to give the 2's complement > [Note] > the representation of positive numbers for sign magnitude, 1's and 2's complement is same #### let's represent -11 as an 8 bit binary number in 2's complement 1. convert 11 in base ten to binary > 11 = 00001011 2. flip every number to get the 1's complement > 00001011 = 11110100 3. to get the 2's complement add 1 > 11110100 + 1 -------- 11110101 > the value of -11 in base ten = 11110101 in base two in 2's complement binary reprentation #### convert answer to hexidecimal 1. To convert answer to hex, first group the value into 4 bit numbers from left to right > 11110101 = 1111 0101 2. find the decimal value for every 4 bit number and put it to it's hex > 1111 = 15 = F > 0101 = 5 3. join the converted value of each 4 bit to give the hexidecimal > 11110101 in base two is equal to 0xF5 ### summary these representation system are usefull because it is how the computer is able to store both positive and negative numbers and perform mathematics