MedVision ad

Negative Minus Negative (1 Viewer)

asergis

New Member
Joined
May 2, 2007
Messages
2
Gender
Male
HSC
2008
Hello
can somebody please explain to the process of subtracting the following
-13-7
i just dont know what do with the negative 13
help?
 

icecoffee

Member
Joined
Jan 11, 2008
Messages
255
Gender
Female
HSC
2008
A negative minus a negative would be more negative. It's easy to see if you draw a number line. So if you start at -13 and you minus 7, you're subtracting more so you're moving to the left of the line (move left 7 spots) and so you'd be at -20.

Is that what you mean?
 

asergis

New Member
Joined
May 2, 2007
Messages
2
Gender
Male
HSC
2008
icecoffee thanks for your reply
but im talking in binary, using twos complement
 

Graceofgod

Member
Joined
Feb 17, 2008
Messages
136
Location
Now? A computer.
Gender
Undisclosed
HSC
2008
Its bump time, oh well, hopefully this helps someone.

13 = 01101
-13 (2's comp) = 10011

7 = 00111
-7 (2's comp) = 11001

-13 + -7

10011
11001+
01100 (2's comp) (cutting off the extra 1)
= 10100 (normal) = 20
Therefore answer is -20

Of course you could always just get 13 and 7, add them together, and take the twos complement of the answer... =S

And just because I'm bored, a 3rd way:

13 = 01101
-13 (2's comp) = 10011

7 = 00111

(-13) - (7)

10011-
00111 (just do this like a normal decimal subtraction)
01100 (in 2's comp)
= 10100 (20)
Therefore -20 is answer.

Yep, you can choose any method you want, they all work.
 
Last edited:

Zippora

Member
Joined
Aug 5, 2008
Messages
161
Location
Sydney
Gender
Female
HSC
2008
Graceofgod said:
Its bump time, oh well, hopefully this helps someone.

13 = 01101
-13 (2's comp) = 10011

7 = 00111
-7 (2's comp) = 11001

-13 + -7

10011
11001+
01100 (2's comp) (cutting off the extra 1)
= 10100 (normal) = 20
Therefore answer is -20
it dont get it, is it a software thing?
 

Graceofgod

Member
Joined
Feb 17, 2008
Messages
136
Location
Now? A computer.
Gender
Undisclosed
HSC
2008
Zippora said:
it dont get it, is it a software thing?
Well, I guess that would explain why it is in Software Design and Development.

Oh well, I will explain anyway.

Two's complement (2's comp) is a way of representing negative numbers in binary so that they can be added and subtracted. It also means that you don't need to know the sign of a number, it can be stored and operations performed on it without knowing if it is positive or negative.

You find a 2's comp of a number by changing all the 1's to 0's and 0's to 1's, then adding a 1 to the end and cutting off any extra bits (outside of the range).
 

crammy90

Member
Joined
Mar 26, 2006
Messages
264
Gender
Male
HSC
2008
Graceofgod said:
Its bump time, oh well, hopefully this helps someone.


10011
11001+
01100 (2's comp) (cutting off the extra 1)
= 10100 (normal) = 20
Therefore answer is -20
so i get how = 10100 is 20 but how does it know its minus 20 ?
 

Graceofgod

Member
Joined
Feb 17, 2008
Messages
136
Location
Now? A computer.
Gender
Undisclosed
HSC
2008
crammy90 said:
so i get how = 10100 is 20 but how does it know its minus 20 ?
Well when you change it from 2's complement it equals 20.
Ie, when you take away the negative sign it is 20.

..10011
..11001+
101100

Note the first bit is a 1, therefore negative
You then cut off first bit (as it is only 5 bits total)
= 01100

You then change from 2's comp (ie take away the negative sign)
= 10100
= 20 in decimal

Get it now?

Although this is a very poor example =S As there is no space for a sign bit... You can have times where the cut off digit is a 1, but it is positive. See below.
 
Last edited:

Graceofgod

Member
Joined
Feb 17, 2008
Messages
136
Location
Now? A computer.
Gender
Undisclosed
HSC
2008
Ok, using 8 bits (to make it much clearer hopefully):

13 = 00001101
-13 (2's comp) = 11110011

7 = 00000111
-7 (2's comp) = 11111001

..11110011+
..11111001
111101100

Cutting off lead:
11101100
The first bit is a 1, therefore it is negative.
Using 2's comp to remove negative sign:
00010100
= 20 (decimal)
 
Last edited:

crammy90

Member
Joined
Mar 26, 2006
Messages
264
Gender
Male
HSC
2008
Graceofgod said:
Ok, using 8 bits (to make it much clearer hopefully):

13 = 00001101
-13 (2's comp) = 11110011

7 = 00000111
-7 (2's comp) = 11111001

..11110011+
..11111001
111101100

Cutting off lead:
11101100
The first bit is a 1, therefore it is negative.
Using 2's comp to remove negative sign:
00010100
= 20 (decimal)
i think i get it now..so if it has a leading 1 in 2's comp when we put it back into normal form its negative whatever that number is, if it has a leading 0 in 2's comp when we put it into normal it is positive whatever the number is?
 

Graceofgod

Member
Joined
Feb 17, 2008
Messages
136
Location
Now? A computer.
Gender
Undisclosed
HSC
2008
crammy90 said:
i think i get it now..so if it has a leading 1 in 2's comp when we put it back into normal form its negative whatever that number is, if it has a leading 0 in 2's comp when we put it into normal it is positive whatever the number is?
If the leading digit is a 1, it is negative. You must apply 2's comp (swap then +1) then convert to decimal to get the value of the number (well a positive version of it, just add a negative sign).
If the leading digit is a 0, then coversion to decimal gives the value.

The only one this doesn't apply to (I think) is 10000000. This is a positive number.
When you perform 2's comp on it, you still get 10000000. This is the extra number (128) given by 2's comp over 1's comp (as it replaces the negative 0 in 1's comp).
 

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

Top