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.

Binary Subtraction

thebokygeek

Newbie
Joined
Oct 8, 2021
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
15
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.
 

dick_freebird

Advanced Member level 5
Joined
Mar 4, 2008
Messages
7,449
Helped
2,158
Reputation
4,321
Reaction score
2,035
Trophy points
1,393
Location
USA
Activity points
59,622
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.
 

KlausST

Super Moderator
Staff member
Joined
Apr 17, 2014
Messages
20,531
Helped
4,463
Reputation
8,935
Reaction score
4,496
Trophy points
1,393
Activity points
135,752
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:

LaTeX Commands Quick-Menu:

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top