Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Binary Subtraction

Status
Not open for further replies.

thebokygeek

Newbie
Joined
Oct 8, 2021
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
33
How can I subtract 5 from 7

i) Binary representation of 5 is (0101)2. The 1’s complement of 5 is then: (1010)2

ii) 2’s complement of 5 = (1’s complement of 5 + 1) = (1010 + 1)2 = (1011)2.

iii) Now, 7 + (-5) = 0111 + 1011 = (1)0010

Any help?

Was taken the reference from here.
 

He,

well done. The solution is correct.

What help do you expect?


Klaus
 

Probably wants to know what to do with the overflow bit and the justification for it.

Been too long since school for me to remember more than the 2's comp, add trick.
 
Hi,

the OP gives a link to an internet page where everything is explained in detail.

it also explains the extension of the sign bit.

4 bits can be
* 4 bits unsigned or (range: 0...15)
* 3 bits plus sign (-8...0...+7)

adding or subtracting two values (in every number system) needs to add one column or digit.
in decimal if we have one digit: 0..9 and add another values of one digit (0..9)
you get values from (0 + 0) = 0 to (9 + 9) = 18 --> 2 digits.

in binary:
if you add 4 bits unsigned (0b0000...0b1111) (in decimal 0...15) and another 4 bits unsigned (0b0000...0b1111) (in decimal 0...15)
you get results from 0b0000 + 0b0000 = 0b0000
to 0b1111 + 0b1111 = 0b11110 (in decimal 15 + 15 = 30)

if you add 4 bits signed (0b1000...0b0111) (in decimal -8...+7) and another 4 bits signed (0b1000...0b0111) (in decimal -8...+7)
you get results from 0b1000 + 0b1000 = 0b10000 (in decimal: -8 + -8 = -16)
to 0b0111 + 0b0111 = 0b01110 (in decimal 7 + 7 = 14)

Klaus
 
Last edited:
Binary subtraction is also similar to that of decimal subtraction with the difference that when 1 is subtracted from 0, it is necessary to borrow 1 from the next higher order bit and that bit is reduced by 1 (or 1 is added to the next bit of subtrahend) and the remainder is 1.
and your answer is correct
 

with the difference that when 1 is subtracted from 0, it is necessary to borrow 1 from the next higher order bit and that bit is reduced by 1 (or 1 is added to the next bit of subtrahend) and the remainder is 1.
Hi,

Binary:
when 1 is subtracted from 0, it is necessary to borrow 1 from the next higher order bit and that bit is reduced by 1 (or 1 is added to the next bit of subtrahend)

Decimal:
when 1 is subtracted from 0, it is necessary to borrow 1 from the next higher order bit and that bit is reduced by 1 (or 1 is added to the next bit of subtrahend)

*********

From the internet:
there are 10 different kinds of people. those who understand binary and those who don't

;-)

Klaus
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top