wpe41.gif (23084 bytes)CIS3355: Business Data Structures
Fall, 2008
 

How do we store negative numbers ?

In decimal we represent negative and non-negative with the use of a sign:

   + 45  is the value non-negative 45
    - 45  is the value negative 45

Notice that there are only two 'values' that the sign can take: + or -

So ???

The sign is used to represent a binary condition.

So ???

We already know that a binary condition can be represented by a single bit (remember our light switches). Therefore, no matter how many bits we have (e.g., 8, 16, 32, 64), we need only to designate one of them as the sign bit (for example, the left-most bit):

Notice, however, that while we still have the same total number of bits, since one bit is designated as the sign, we have one fewer bit to represent the integer value:

That will change the range of our integers:

Integer Type

Number Bits

Negative/Non-Negative Integer Range

Numeric Byte 1 + 7 -27 to +27 -1
-128 to + 127
Short Integer 1 + 15 -215 to +215 -1
-32,768 to +32,765
Integer 1 + 31 -231 to +231 -1
-2,147,483,648  to +2,147,483,647
Long Integer 1 + 63 -263 to +263 -1
-9,223,372,036,854,775,808 to +9,223,372,036,854,775,807

HOWEVER, the total number of combinations remains the same.

Why do you subtract 1 from the largest non-negative integer ???
For example:
-231 to +231 - 1 ???

Don't forget, we need to be able to represent the integer 0 (zero).

What values do we put into the sign-bit ???

We only have two possible values: '0' or '1'. Let's say that if the number is negative, we will store the binary number '1' in the sign bit; If the number is non-negative, we will store the binary number '0' in the sign-bit.

Following our logic, that means that we would store the the value +56 (as a short integer) as:

Further following our logic, that means that we would store the value -56 as:

Now, of course, if we add +56 and -56, we should come-up with the value 0 (zero):

Which evaluates to the negative value (based on our sign-bit):

- (26 + 25 + 24) = -(64 + 32 + 16) = -112

WHAT !!! 56 + -56 = -112 ??? What's going on ???

Well some of our ideas were good (e.g., the use of the sign bit), but we need to refine our procedures a little bit.

How ???

We first need to investigate the concept of complementing numbers.

You need to say 'Nice number' ???

No, not that kind of complementing. We will take a look at the concept in the next tutorial.

Some questions you should be able to answer:

  1. A sign can either be negative or non-negative. This means that the use of a sign is a:

a.  conceptual illusion                d.  binary value
b.  binary condition                    e.  imaginary condition
c.  conditional modifier

Answer: B

  1. If I had 24-bits which were grouped together, and I designated one of the bits as a sign-bit, what is the range integers I could represent?

a.  -27 to +27 -1                d.  -223 to +223 -1
b. 
-224 to +224 -1             e.  0 to +223 -1
c. 
0 to +224 -1

Answer: D

  1. How would I store the value +48 (as a short integer), where the left-most bit is the sign-bit?

This page was last updated on 05/30/05