Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Problem subtracting binary's
Replies: 2   Last Post: Nov 21, 1996 5:49 PM

 Messages: [ Previous | Next ]
 Philip M. D'Amato Posts: 4 Registered: 12/6/04
Re: Problem subtracting binary's
Posted: Nov 21, 1996 2:40 PM

Without compliments, by converting to decimal
1010 is 10 decimal
- 0011 is 3 decimal
------
= 0111 is 7 decimal

This is unrealistic if given in the context of a computer doing the math.
On x86 systems (and possibly others) the following assembly language
instruction represents 10-3:
SUB AL,3 ;where the AL register stores the value 10
What is really happening at the bit level is that the immediate (constant)
value 3 is negated (by two's compliment), so:
00000011 (3) becomes
11111101 (-3)
and is then added to the value in AL (in this example). So, 10-3 becomes
10+(-3), or:
00001010
+ 11111101
-----------
= 100000111 ;the most significant (left-most) bit is "overflow", and is
lost.
In these examples, I've represented 8 bit values, rather than the 4 bits in
your problem, but the method still holds true. As a further note, the SUB
operation works for both signed and unsigned arithmetic. In this example,
it is entirely up to the programmer to determine whether 11111101
represents -3 decimal or +253 decimal! This is accomplished by
interpreting the Sign and Carry Flag status in the x86 flags register. In
the above example, OF (the Overflow Flag) is set, and CF (the Carry Flag)
is clear (but I digress).

Hope this helps.
--
Philip M. D'Amato
pdamato@msn.com
"Any opinions expressed are not necessarily my own."

Roger Simms <roger@switch.demon.co.uk> wrote in article
<329772a6.314757144@news.demon.co.uk>...
> Can some one help me with this simple problem that's driving me mad.
>
> 1010
> -0011
> ----
> 0111
>
> Not using compliments just by borrowing and paying back I just cannot
> see where you are meant to be borrowing from and where you are paying
> back to
>
>
> If any one can help i would be gratefull.
>
>
> +===============================================================+
> | I'm as old as my tongue and a little bit older than my teeth |
> | And I hope to keep both |
> | ************************** |
> |Roger Simms *Definition of Maturity * |
> |Sutton *When you start worrying * |
> |England *about Insurance * |
> | ************************** |
> +===============================================================+
>

Date Subject Author
11/21/96 Philip M. D'Amato
11/21/96 Gary