BInary subtraction questions (1 Viewer)

Seraph

Now You've done it.......
Joined
Sep 26, 2003
Messages
897
Gender
Male
HSC
N/A
Okay im a bit confused here

What exactly is the difference between Ones complement and twos complement?

Ive been reading the textbook but its just been confusing me ... so ive been reading some ppls notes at this site and it looks like they use exactly the same process!!! ??????
there has to be a difference...

and also where does sign modulus come into play when using these complement methods???? you know representing negatives with an extra bit (1 for negative 0 for positive)... ???
 

redruM

Breathe and Stop
Joined
May 11, 2004
Messages
3,954
Gender
Male
HSC
2003
fatmuscles notes for this bit helped i remember...u had a look at them?
 

juventino

Juventus For Life
Joined
Jun 4, 2003
Messages
385
Location
Western sydney ;)
Gender
Male
HSC
2004
AHHH yo Mazz , mad piss easy

ones' compliment is the digits switched eg 111000 turns into 000111

and two's compliment is the ones compliment +1

that's all

and me is no understand your second question....:(

what really shits me about this topic is division in binary...worst eva
 

Seraph

Now You've done it.......
Joined
Sep 26, 2003
Messages
897
Gender
Male
HSC
N/A
Ok hang on Fatmuscles Binary Subtraction Notes:
One's Complements
! Bottom number is reversed. 0's become 1's; 1's become 0's. Remember: spaces
are counted as 0's.
! Add top and reversed bottom number together.
! Add one bit to the result
! The leading 1 is removed.

yea that makes sense however One of his methods in :
two complements :
! Change the bottom number. All numbers are reversed. 0's become 1's; 1's
become 0's. Remember: spaces are counted as 0's. Add 1 bit.
! Add top and changed bottom number together.
! The leading 1 is removed.

very similar??
 

acmilan

I'll stab ya
Joined
May 24, 2004
Messages
3,989
Location
Jumanji
Gender
Male
HSC
N/A
For binary subtraction:

Use 11011 - 10100 as an example (ie 27 - 20 in base 10)

To find 1's complement, reverse digits of second number ie 1's become 0's and 0's become 1's for the eg. 10100 forms 01011 in 1's complement

To find 2's complement, add 1 to the 1's complement
01011 + 1 = 01100 and ignore the carry for the last addition (so the amount of digits in the 2's complement is the same as in the 1's complement).

Then add the first number in the original subtration with the 2's complement:
11011 + 01100 = 00111 and again ignore the last carry (which was 1 in this case). The result is 00111, which is 7 in base 10, which is the answer to the original subtraction (remember than in base 10 it was 27 - 20 = 7)
 

Seraph

Now You've done it.......
Joined
Sep 26, 2003
Messages
897
Gender
Male
HSC
N/A
yea i know but what exactly is it doing when this complement thing happens ?

is it just another method of representing negative numbers?
 

sunny

meh.
Joined
Jul 7, 2002
Messages
5,350
Gender
Male
HSC
2002
Yes. 2s complement is just a way of representing negative numbers.
 

Seraph

Now You've done it.......
Joined
Sep 26, 2003
Messages
897
Gender
Male
HSC
N/A
and the 1's complement ?? another way?


So when you represent these numbers
for instance -2 represented as
1101 in 2's complement , you cant actually do any binary calculations to work out the number is 2..

uhh then how are you supposed to know if they just gave you 1101 and said what negative 2's complement number is this representing (in decimal) .. ?

and one more thing is it possible to do say 10 - 12 ?
or -20 - 10 ? using this system
 
Last edited:

Winston

Active Member
Joined
Aug 30, 2002
Messages
6,128
Gender
Undisclosed
HSC
2003
Basically the 2's compl system represents a negative number, if you perform 2's compl on a 2's compl number it will give u the positive value, and this is how it shows the 2's compl actually represents a negative number, or there's also Sign Bit representation of a negative number where by 1 is negative and 0 is positive, however the sign bit is not taken into account for the magnitude.
 

sunny

meh.
Joined
Jul 7, 2002
Messages
5,350
Gender
Male
HSC
2002
Originally posted by Seraph
and the 1's complement ?? another way?


So when you represent these numbers
for instance -2 represented as
1101 in 2's complement , you cant actually do any binary calculations to work out the number is 2..

uhh then how are you supposed to know if they just gave you 1101 and said what negative 2's complement number is this representing (in decimal) .. ?

and one more thing is it possible to do say 10 - 12 ?
or -20 - 10 ? using this system
There isn't actually any relationship between 1s and 2s complement. It just so happens that adding 1 to a number in 1s complement will give you 2s complement. There are many different types of complements...

Take -9 for example, in:
signed magnitude = 10001001
1s complement = 11110110
2s complement = 11110111

A even quicker way of getting the 2s complement of a binary number is to leave all the least significant 0s and the least significant 1 unchanged, and then replacing 1s with 0s and 0s with 1s in all the other higher bits.

Eg, 6 is 0110. Ignore the least significant zeros, and the least significant 1, then complement all the other bits => 1010.

-2 in 2s complement is not 1101.
Lets do this one step by step.

2 in binary is 0010
Take the 1s complement (complement all bits), this becomes 1101.
Add 1 to 1s complement to get 2s complement: 1101+1 = 1110

Now, for example, if you wanted to do 3-2, you do not actually need to do any subtraction; you add 3, and the two's complement of 2 togther.

ie, you add 0011 and 1110

0011 + 1110 = 10001
Ignore the carry and you get 0001. Positive 1, which is 3-2.

Now lets do your example of 10-12.

10 in binary is 01010
12 in binary is 01100

Take the 2s complement of 12
01100=> 10011 => 10011+1 => 10100

Now add binary 10, and 12 in 2s complement
01010
10100 +

11110 is the result.

The most signifcant bit is a 1, indicating the subtrahend was bigger than the minuend and resulted in a negative result. This means, the current result is really the result in 2s complement.

To correct this (called 2s complement correction), take the 2s complement of this number:

11110 => 00001 => 00001 + 1 => 00010

This is +2, however, since the original problem was that the result was -ve two, you have to keep in mind that this is really -ve 2.

You can rewrite this in signed magnitude: 10010 to indicate it is -2.

Notice in the first example, 3-2, the initial result was 0001, which does not have a 1 in the MSB, indicating the result is positive and does not need to go through 2s complement correction.


Hope that helps.
 
Last edited:

Seraph

Now You've done it.......
Joined
Sep 26, 2003
Messages
897
Gender
Male
HSC
N/A
alright one more thing

in 3 bit ascii why is the 2's complement of 0 (000) = 100?

shouldnt it be

111
+ 1
= 1000 which im curious to know why it is even represented in 3 bit ascii!?

if it is 100 the 2s complement is - 4 then??? that is very strange since i thought normally all the 2s complements have to be corresponding ,( e.g 3 2's complement is -3)
 

sunny

meh.
Joined
Jul 7, 2002
Messages
5,350
Gender
Male
HSC
2002
The 2's complement of zero is a special case. Usually in other representations there are two representations of zero; positive 0 and negative 0. In 4 bit signed magnitude for example, positive zero is 0000 and negative zero is 1000.

In 2's complement, there is only one representation of zero: positive zero (000).

There is no negative zero in 2's complement.

Hope that helps.
 

screw_uni

New Member
Joined
Aug 19, 2004
Messages
9
Exam::20o4

I have a software exam in 1 hour and I don't even know how to add, subtract, divide or multiply binary or CONVERT either and its for my HSC Trial... man im so screwed!

Anyway... back to 'studying'!
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top