3.5.5+Negative+integers+in+binary

= **Note: This page needs to be revised. Some information might be incorrect.** = =**__Representing integers (positive and negative) in binary__**= In computers, negative numbers are stored as binary numbers using complementary arithmetic. This means subtractions can be handled just like additions, simplifying the computer's design.

In this system the most significant bit (MSB) represents a negative value. In a 4-bit system, for example, it would look as follows: Another way to think of this, is to think of the MSB as the indicator whether the number is negative (1) or positive (0).
 * __Two's complement method__**
 * < Decimal ||= -8 ||= 4 ||= 2 ||= 1 ||
 * < Binary ||= 1000 ||= 0100 ||= 0010 ||= 0001 ||
 * < Powers of 2 ||= -2media type="custom" key="8789386" ||= 2media type="custom" key="8789388" ||= 2media type="custom" key="8789392" ||= 2media type="custom" key="8789382" ||

Say you have a 3 in a 3-bit system (i.e. 011) and want to convert it into a negative number.
 * __Calculating negative numbers using the 2's complement__**

__Method 1:__ These two videos are very helpful to understand this method of representing negative numbers in binary: Part 1: http://www.youtube.com/watch?v=9W67I2zzAfo#t=7m20s Part 2: @http://www.youtube.com/watch?v=Hof95YlLQk0 Another good explanation of this method of representing negative numbers is here: http://everything2.com/user/Lyon/writeups/twos+complement
 * 1) Take the binary representation of the number (011) and flip the bits = 100
 * 2) Add 1 (001): 100+001 = 101

__Method 2:__ You can calculate the binary representation of a number just as with positive numbers, if you keep in mind, that the MSB is a negative number. We know, that the values in a 3-bit 2's complementary system are as follows: Using the values of the table above, we can create -3 by taking the negative number (-4 in this case) and adding positive numbers to it using the other bits, to create the desired value. -4+1=-3 i.e. 100+001=101
 * Decimal || -4 || 2 || 1 ||
 * Binary || 100 || 010 || 001 ||
 * Powers of 2 || -2media type="custom" key="8789388" || 2media type="custom" key="8789392" || 2media type="custom" key="8789382" ||

Last edit by: Jocbe Last update: 22. March 2011

Sources:
 * Jones, Richard. Computer Science Java Enabled. Victoria: IBID Press, 2004.
 * Protowise. "Two's Complement Part 1 - An Introduction." YouTube - Broadcast Yourself. Google, 27 May 2009. Web. 22 Mar. 2011. .
 * Protowise. "Two's Complement Part 2 - An Introduction." YouTube - Broadcast Yourself. Google, 28 May 2009. Web. 22 Mar. 2011. .