Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

binary subtraction using 2's complement

Status
Not open for further replies.

tejasvi

New Member
how do i calculate binary subtraction of 0000-0001 using 2's complement
my calculation looks like this
0001 >complement= 1110 > adding 0001 = 1111
finally adding it to
0000
1 1 1 1
-------
1 1 1 1 which is wrong

but in reverse i get correct answer
0000 >complement= 1111 > adding 0001 = 0000
0000
0001
-------
0001 which is correct
 
Are you asking " how do I form the twos complement of an integer?", or "how do I do subtraction using twos complement?"
 
how do i calculate binary subtraction of 0000-0001 using 2's complement
my calculation looks like this
0001 >complement= 1110 > adding 0001 = 1111
finally adding it to
0000
1 1 1 1
-------
1 1 1 1 which is wrong

No it's not. You don't understand 2's complement arithmetic. 1's complement arithmetic has a plus zero (0000) and a negative zero (1111). 2's complement arithmetic has only a positive zero (0000). Therefore, 1111 represents -1 decimal in 2's complement arithmetic and your answer is correct.

but in reverse i get correct answer
0000 >complement= 1111 > adding 0001 = 0000
0000
0001
-------
0001 which is correct
Why are you puzzled when you get a positive one when you add zero to a positive one?

Ratch
 
4 bits in 2's complement would represent -8 to +7. 16 bits represents -32768 to 32767; there is only one zero in 2's complement notation.

The left most bit is the sign bit and you can "sign extend" that. so if you had 1111 (-1) sign extended to 16 bits 1111 1111 1111 1111 is still -1.
So is 0001 (1) sign extended to 16 bits 0000 0000 0000 0001 is still 1.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top