Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Math Topics » alt.math.undergrad.independent

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   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
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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 * |
> | ************************** |
> +===============================================================+
>






Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.