# Binary Subtraction

#### thebokygeek

##### Newbie 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.

#### KlausST

##### Super Moderator
Staff member He,

well done. The solution is correct.

What help do you expect?

Klaus

#### dick_freebird 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.

• thebokygeek

#### KlausST

##### Super Moderator
Staff member 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:
• thebokygeek

#### thebokygeek

##### Newbie He,

well done. The solution is correct.

What help do you expect?

Klaus
I was confused if the solution is correct or not as I am still learning, Thanks for your reply!

## Commands Quick-Menu: 