subtracting two's complement for beginner - binary

Guys need some help to solve a question. I am trying to learning Complement notation which is in my bca course. Recently i finished the 2's complement notation chapter, ans stuck at question.
Can some one describe me that how to subtract
a)10 from 14
b)14 from 10
using 2's complement notation.
What i have done is
Above numbers in binary.
10=1010
14=1110
two's complement of the two numbers.
1010=>0101+1=0110
1110=>1110+1=1111
Now i am stuck how will i solve the
a)Subtraction of 10 from 14
b)Subtraction of 14 from 10
Please use descriptive way so i can understand each step for both subtraction. Thanks in advance.

At last, we have found the solution
10 in binary 00001010
2's complement of 10 is 0110
14 in binary 00001110
2's complement of 14 is 0010
4 in binary 0000 0100
2's complement of 4 is 1111 1100
2's Complement Subtraction=>
10 - 14 = (-4) 0000 1010 = +10
+ 1111 0010 = -14
1111 1100 = -4
2's Complement Addition=>
14 - 10 = (+4) 0000 1110 = +14
+ 1111 0110 = -10
10000 0100 = +4

Once you are done with 2' complement,
You just need to add it.
Subtraction of 14 from 10
1010=>0101+1=0110 [This means -10]
14 + (-10)
1110
+
0110
0100 [Do not worry about the carry]

Subtraction of 10 from 14
10=1010 14=1110
2's complement of 1110 is 0010
1 0 1 0 + 0 0 1 0 = 1 1 0 0
2's complement of 1100 is 0100
10 - 14 = -4
1010 - 1110 =0100

Related

Binary into 2's compliment

if I convert the binary number 000000 into 2's compliment I will get
1's compliment (invert) = 111111
2's compliment (add +1) = here I run into a problem, does this return 000000 and the 1 gets discarded or does this return 1000000?
Thanks in advance!
It discards the 1. The condition is similar to the Arithmetic Overflow.
Strength of two's complement is that it helps us retain a binary representation when signed numbers are to be considered, because in mathematics, the value of 0 is same as that of -0. If we have to give up one entire bit just for sign, then, in a 4-bit word, 0000 would denote 0 and 1000 would denote -0, wasting one representation. The two's complement helps get rid of this. If we assume 4-bit words:
val -val bits of val two's complement bits of -val (1's complement + 1)
0 0 0000 0000 (1111+0001)
1 -1 0001 1111 (1110+0001)
2 -2 0010 1110 (1101+0001)
3 -3 0011 1101 (1100+0001)
...
7 -7 0111 1001 (1000+0001)
8 -8 (no rep) 1000 (0111+0001)
(note that for -8 you have one's complement of 8 in an unsigned manner, i.e.8 = 1000 and hence its one's complement is 0111).
Thus you gain a representation for -8 by making 0 and -0 have the same bit pattern, i.e. 0000. Using this, for n bits, we can represent all integer values between -2^(n-1) to 2^(n-1)-1.

Need help adding with Twos Complement notation

I'm having slight confusion over two's complement. I have reviewed What is “2's Complement”?.
I'm trying to add -2 + -3 = -5. Here's my thought process:
+2 = 0010
-2 = 1110 # in twos complement
+3 = 0011
-3 = 1101 # in twos complement
1101
+1101
-----
10010 # What is this?
I know -5 is 1011 in Two's Complement. But I'm not sure what I did when I added -2 + -3 in the example above.
An explanation of the process to add -2 + -3 would be appreciated. Thank you for your assistance!
In 4 bit 2'scomplement -2 is 1110 and +3 is 0011 so
11110 carry
1110 -2
+0011 +3
----
10001 which is 0001 or simply 1 ignoring the carry in bit 5
Stepping through the process from the right to the left:
1 + 0 results in 1 with no carry
1 + 1 results in 0 with a carry of 1
1 + 0 + the carry of 1 results 0 with a carry of 1
1 + 0 + the carry of 1 results in 0 with a carry of 1
just the carry of 1 results in 1 with nothing more to carry
For reference see the Wikipedia article on 2's complement particularly the section on addition at https://en.wikipedia.org/wiki/Two%27s_complement#Addition. There are a number of online 2's complement calculators to help with conversions and one of them is at http://www.exploringbinary.com/twos-complement-converter/
Let me know if you want to see how -3 + -3 is done, since that is what you attempted. It is a similar process, but be sure start with bit length large enough to avoid overflow as determined when the leftmost two bits in the carry row have different values.

Binary Subtraction with 2's Complement

I need help subtracting with binary using 2's representation and using 5 bits for each number:
1) -9 -7 = ? Is there overflow?
-9 = 01001 (2's complement = 10111) and -7 = 00111 (2's complement = 11001)
Now we need to add because we're using 2's complement
10111
+11001
= 100000 But this answer doesn't make sense. Also, I'm assuming there's overflow because there are more than 5 bits in the answer.
2) 6 - 10, same process as before. Negative binary numbers don't make sense to me
1) -9 - 7
-9 - 7 = -9 + -7
9 (binary) = 01001
-9 (2's complement) = 10111
7 (binary) = 00111
-7 (2's complement) = 11001
10111 +
11001 =
110000
This doesn't fit into 5 bits. Removing the overflow we get 10000, which is -16 (binary).
2) 6 - 10
6 - 10 = 6 + -10
6 (binary) = 00110
10 (binary) = 01010
-10 (2's complement) = 10110
00110 +
10110 =
11100
This fits into 5 bits and is -4 (binary).
10111 + 11001 is not 100000 but 110000.
1111
10111
+ 11001
-----
110000
Answer to the 1st question is wrong. To find -9-7 using two's complement, we need follow these steps:
STEP:1 Convertion of first number
1st the binary conversion of 9: 01001
2nd find the complement of binary: 10110
Add 1 to the binary complement: 10110
+1
-----
10111
STEP 2: Convertion of second number
1st the binary conversion of 7: 00111
2nd find the complement of binary: 11000
Add 1 to the binary complement: 11000
+1
-------
11001
STEP 3: Adding
Now add the two outputs -9 + (-7): 10111
+11001
--------
110000
The most important thing is checking the answer whether it is correct or not.
you may use index for the binary digits: 7 6 5 4 3 2 1 0
1 1 0 0 0 0
find the 2 raised to the power of each index having 1 digit.
(-)2^5 + 2^4
*Note (-) is used because in two's complement, the most significant bit (the bit with the highest index) is a sign bit -2^5 + 2^4 = -32 + 16 = -16
which is the correct answer for -9-7=-16. For this reason 2's complement become a popular way of representing negative number. For sign magnitude we need to assume a sign bit, which is hard to implement in a computer, and for 1's complement we need to add 1 to find the correct answer.

resulting sum in binary 16

I have answered the question but i could not understand the part where its says get the resulting sum in 16-bit binary, check your answer by converting the sum into decimal.
1.Add ‘A’ and ‘B’ in binary to get the resulting sum in 16-bit binary, check your answer by converting the sum into decimal.
Decimal number = 58927634
A= 5892 to Binary 1011 1000 0010 0
B= 7634 to Binary 1110 1110 1001 0
a + b = 11010011010110
thanks alot
Regards
Let me explain:
A = 00005892
B = 00007634
in base 10 number system, with 8 decimals to represent it.
and...
A = 0001 0111 0000 0100
B = 0001 1101 1101 0010
in base 2 number system, with 16 bits to represent it.
I hope it makes sense to you now.
And the sum of A and B, in base 2 number system with 16 bits to represent it....
0011 0100 1101 0110
although, we needed just 14 bits....
Your answer is correct, but its width is 14 bits long.

Help understanding Binary Representation for Integers?

I'm trying to understand these illustrations but there are parts which I don't understand:
"But the computer had to count backwards for the negative numbers"
Why does adding a 1 to the front of a binary mean the computer has to count backwards?
"Flip the bits and add 1!"
What does that mean add 1?
woops: http://csillustrated.berkeley.edu/PDFs/integer-representations.pdf
This may be easiest to show by example. Here are the numbers from -4 to 4 represented in binary:
4 0000 0100
3 0000 0011
2 0000 0010
1 0000 0001
0 0000 0000
-1 1111 1111
-2 1111 1110
-3 1111 1101
-4 1111 1100
So say we want to go from 1 to -1. We first flip all the bits of 1
1 0000 0001
flip bits
-----------
1111 1110
Then we add a 1:
1111 1110
+ 1
-----------
1111 1111
We now have -1.
I'm not seeing the illustrations, but you're probably talking about Two's complement representation. (http://en.wikipedia.org/wiki/Two's_complement)
Why does adding a 1 to the front mean the computer has to count backwards?
Due to how carrying works, FFFFFFFFF + 1 == 0
and 0 - 1 == FFFFFFFF. All the bits get flipped, including the first bit.
If you simply define the negative numbers as those starting with a 1 bit (80000000 - FFFFFFFF) then you get a nice uniform behavior for addition with a natural overflow.
Flip the bits and add 1: in 2's complement, this negates a number
~x+1 == -x; // always true
What you're talking about is called signed integers.