|


Negative Numbers in BinaryDate: 08/19/99 at 17:06:35 From: Ramesh Akella Subject: Binary Number How do I represent -53 as a binary number? Is it 110101? Wouldn't that be +53? Can you help me?
Date: 08/19/99 at 22:58:21
From: Doctor Peterson
Subject: Re: Binary Number
Hi, Ramesh.
Mathematically, there's nothing wrong with writing -53 as -110101,
using a separate negative sign as we do in decimal. In computers, the
usual method for storing signed numbers is called "twos-complement":
to negate a number, you take the complement (changing 0 to 1 and
1 to 0) and add 1:
53 --> 00110101
-53 --> 11001010 + 1 = 11001011
Since any negative number has the leftmost bit set, the effect of this
is to take the upper half of the range of numbers that can be stored
in a fixed number of bits (eight bits in my example) and use them for
negative numbers. The numbers 0 to 127 are positive; numbers 128 to
255 represent -128 to -1. You can still add two numbers just as you do
with unsigned numbers:
-53 = 11001011
+ 63 = 00111111
----- -----------
10 = (1)00001010
In this case an extra carry digit is generated, but it is ignored and
the result is the correct answer.
You can learn more about this by using a searcher like Google
(http://www.google.com/) to look for the phrase "twos complement."
- Doctor Peterson, The Math Forum
http://mathforum.org/dr.math/
|
Search the Dr. Math Library: |
[Privacy Policy] [Terms of Use]


Ask Dr. MathTM
© 1994-2013 The Math Forum
http://mathforum.org/dr.math/