Vous êtes sur la page 1sur 7

# In the early days of computing, designers made computers express numbers using unsigned binary.

## To include negative numbers, designers came up with sign magnitude.

Then designers created ones complement.
Finally, designers developed twos complement.
But the computer had to count backwards
for the negative numbers.
Plus, this introduced positive and negative zero.
Hey guys! How
do you negate
numbers?
Comparing Integer Representations
Negation and Zeroes
Hi! And welcome to the Best Integer
Representation competition!
Here, well choose who gets to be the
worlds standard for computer integers!
But first, lets introduce our contestants:
Round 1 - Negation
Round 2 - Zeroes
In this competition, well use 8-bit numbers. Now lets get started!
Unsigned Sign
Magnitude
Ones
Complement
Twos
Complement
Bias
Flip sign bit
Flip all bits
Flip all bits
Subtract
from 12710
Oh, dear! It looks like Unsigned cant negate. But this competition has only
started, so Unsigned still has a chance of catching up to the others.
0000 0000
1000 0000
0
0
0
0
0
0
0
0
1 1 1 1 1 1 1 1
0111 1111
0
0
0
0
0
0
0
0
Now things are getting interesting! Unsigned and Twos Complement get two points each
for having one zero and being able to represent zero with all zero bits. Biass zero isnt all
zero bits, but it gets a point for having only one zero. And though they have two zeroes,
Sign Magnitude and Ones Complement get a point for having a zero of all zero bits.
Round 1 is easy. Just tell me
how you negate a number!
Now for Round 2! Show me
all the ways you represent
zero!
Um...
0000 0000
-12710
-
1
2
7
1
0
-
1
2
7
1
0
0 1 1 1 1
2 2 2 3 2
255
0
-255
128
-128
00000000 01111111 11111111
1
-1
127
-127
10000000
255
0
-255
128
-128
00000000 01111111 11111111
1
-1
127
-127
10000000
255
0
-255
128
-128
00000000 01111111 11111111
1
-1
127
-127
10000000
255
0
-255
128
-128
00000000 01111111 11111111
1
-1
127
-127
10000000
255
0
-255
128
-128
00000000 01111111 11111111
1
-1
127
-127
10000000
Comparing Integer Representations
Increments and Monotonicity
Round 3 - Incrementing
255
0
-255
128
-128
00000000 01111111 11111111
1
-1
127
-127
10000000
Very nice! Unsigned has a graph that is continuous
and has a unit slope. This means we can use an
unsigned comparator to compare integers!
Well give Unsigned two points for that.
Whats this? Sign Magnitude has a very unusual
increment indeed. It has a unit slope for positive
integers, but the slope becomes -1 for negatives.
Sorry, but no points for Sign Magnitude this round.
Another monotonically increasing graph with unit
slope! You can use an unsigned comparator to
compare integers here, too. Bias gets two points!
Just like Ones Complement, Twos Complement
has a discontinuous graph and unit slope. So
well give Twos Complement a point.
Theres a discontinuity in the graph for
Ones Complement, but we do like how
it has a consistent unit slope.
Thats one point for Ones Complement.
4
2
3
4
4
-
1
2
7
10
On to Round 3! Using this board, graph how your value changes when you
increment your bit pattern from 00000000 to 11111111! Well give each player
a point for having a continuous graph and a point for a consistent unit slope.
Unsigned
Sign Magnitude
Ones Complement
Twos Complement
Bias
Comparing Integer Representations
The Thrilling Conclusion!
One Zero? Negation?
Zero =
0000 0000
Monotonically
Increasing?
Continuous?
Weve finally arrived at the
end of our competition. Lets
see that scoreboard!
Well, well! It appears we have a three-way tie among Unsigned, Twos Complement,
and Bias! We can certainly give each of our winners a prize, though!
Unsigned, youll be the representation
for data whenever users call upon the
unsigned modifier in C! Ive heard that
other languages use it, too, so youll
work for them as well.
Bias, youll represent the exponent in
IEEE-754 floating-point numbers! The
fact that we can compare exponents
with an unsigned comparator will come in
handy!
And you, Twos Complement, because
you can negate and have one zero that
is expressed as all zero bits, you will be
the representation of integers for
binary computers all around the world!
-
1
2
7
1
0
unsigned char foo = 24;
000110002
signed char bar = -24;
111010002
3.141592
Floating-Point Numbers!
An IEEE 754 floating point number consists of three parts:
(Also known as the Significand)
the Exponent, the Sign, and the Mantissa.
The Sign, as its name suggests,
determines the sign of the number.
The Exponent plays a vital role in determining
how big (or small) the number is. However, its
encoded so that unsigned comparison can be
used to check floating-point numbers.
To see the true magnitude of the
Exponent, youd need to subtract the
Bias, a special number determined by
the length of the Exponent.
And last but not least, the Mantissa
holds the significant digits of the
floating point number.
+
100000002
0100000
0
0
0
0
0
0000000000
0
2
-12710
Floating-Point Numbers:
All Together Now!
010000000
0
0
00000000000
0
2
+
Once all the parts of the floating-point number are obtained, converting
it to decimal is just a matter of applying the following formula:
Notice that the Mantissa actually represents a fraction, instead of an integer!
In addition to representing real numbers, the IEEE 754 representation can also indicate...
positive or negative infinity,
and even when something is not a
number! This is called NaN.
+
111111112
00000000
0
0
0
0
0000000000
0
2
-
-
111111112
+
the set of numbers known as denormalized
numbers (including zero),
+
-
-12610
-12710
Example:
=02
NaNs arent
comparable, but
they can be
different!
If this is all zeroes,
the float is zero!
Floating-Point Numbers:
The Great Number Line
Due to the format of the IEEE-754 standard, the floating-point numbers can be plotted on a number line.
In fact, the floating-point numbers are arranged so that they can be incremented like a binary odometer!
NaN
+ Floating
Point
Number
+ Denormalized
Number
+ 0
-
-
-
+
-