0% found this document useful (0 votes)
34 views

Numbers: Unsigned

This document discusses different ways that the binary numbers from 0000 to 1111 (0 to 15 in decimal) can be interpreted as numeric values or encodings. It examines unsigned binary, two's complement, one's complement, signed magnitude, BCD, 3-bit unsigned with parity, Gray code, fixed point, and floating point interpretations of the bit patterns. The document also presents a made-up interpretation as an example of how meaning can be arbitrarily assigned to bit patterns.

Uploaded by

hibolelbi
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Numbers: Unsigned

This document discusses different ways that the binary numbers from 0000 to 1111 (0 to 15 in decimal) can be interpreted as numeric values or encodings. It examines unsigned binary, two's complement, one's complement, signed magnitude, BCD, 3-bit unsigned with parity, Gray code, fixed point, and floating point interpretations of the bit patterns. The document also presents a made-up interpretation as an example of how meaning can be arbitrarily assigned to bit patterns.

Uploaded by

hibolelbi
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

2/1/13

Numbers

Numbers
Here's a interesting question that can be used to judge how much a computer programmer really knows about the machine. Write out the bit patterns from 0000 to 1111 and ask, "How many different numbers can you get from this.
0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0 0 1 0 1 0 1 1 0 0 1 1 1 1 0 0 0 1 0 0 1 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 1 1 1 1 0 1 1 1 1

Here's a list of the answers I've come up with.

Unsigned
The simple binary numbers 0 through 15.
0 0 0 00 1 0 0 0

8 0 0 0 11 1 0 0 1 9 0 0 1 02 1 0 1 010 0 0 1 13 1 0 1 111 0 1 0 04 1 1 0 012 0 1 0 15 1 1 0 113 0 1 1 06 1 1 1 014 0 1 1 17 1 1 1 115

Two's complement
We get the numbers 7 to -8.
0 0 0 00 1 0 0 0-8 0 0 0 11 1 0 0 1-7 0 0 1 02 1 0 1 0-6 0 0 1 13 1 0 1 1-5 0 1 0 04 1 1 0 0-4 0 1 0 15 1 1 0 1-3 0 1 1 06 1 1 1 0-2 0 1 1 17 1 1 1 1-1

One's complement
www.oualline.com/practical.programmer/numbers.html 1/4

2/1/13

Numbers

Some of the older computers actually used 1's complement because it was simpler to design some 1's complement circuits. The problem with 1's complement is the existence of negative 0. The numbers range from 7 to -7 including 0 and -0.
0 0 0 00 1 0 0 0-7 0 0 0 11 1 0 0 1-6 0 0 1 02 1 0 1 0-5 0 0 1 13 1 0 1 1-4 0 1 0 04 1 1 0 0-3 0 1 0 15 1 1 0 1-2 0 1 1 06 1 1 1 0-1 0 1 1 17 1 1 1 1-0

Signed magnitude
We actually used signed magnitude in our everyday life. It's used for normal decimal integers. We have a sign character, followed by a number of digits of magnitude. For our bit patterns, signed magnitude gives number from 7 to -7 with 0 and -0. However, we don't use the same bit patterns as 1's complement.
0 0 0 00 1 0 0 0-0 0 0 0 11 1 0 0 1-1 0 0 1 02 1 0 1 0-2 0 0 1 13 1 0 1 1-3 0 1 0 04 1 1 0 0-4 0 1 0 15 1 1 0 1-5 0 1 1 06 1 1 1 0-6 0 1 1 17 1 1 1 1-7

BCD
Binary Coded Decimal uses 4 bits to represent a single digit. It was used extensively in financial calculations. Things like updating a billing record where the cost of converting to binary was expensive considering that only a few simple operations needed to be performed with the numbers. So using BCD we get a single digit, which leaves us with the numbers 0-9 and 6 illegal bit patterns.
0 0 0 00 1 0 0 0 0 0 0 11 1 0 0 1

9 0 0 1 02 1 0 1 0illegal
www.oualline.com/practical.programmer/numbers.html 2/4

2/1/13

Numbers

0 0 1 13 1 0 1 1illegal 0 1 0 04 1 1 0 0illegal 0 1 0 15 1 1 0 1illegal 0 1 1 06 1 1 1 0illegal 0 1 1 17 1 1 1 1illegal

3 bit unsigned with parity


We can make the first bit a parity bit. Parity is a very simple error checking system. When have even parity, an even number of bits are set to 1. When you have odd parity an odd number of bits are set. If we use 3 bit unsigned with even parity we get the numbers 0-7 and 8 other bit patterns which contain a parity error.
0 0 0 0 0 0 0illegal 01

0 0 0 1illegal 1 0 0 1 0 0 1 0illegal 1 0 1 0 0 0 1 1 0 1 0 0illegal 1 1 0 0 0 1 0 1 0 1 1 0

2 0 1 1illegal 31 4
1 0 1illegal 51 1 1 0illegal 61

0 1 1 1illegal 1 1 1 1

Gray code
In Gray code only one bit changes at a time. That makes it very useful for position encoders. Straight binary is not very good for this job. Think about what would happen if we used straight binary for an encode and positioned the device exactly on the bounder between 7 and 8. Each bit could be on or off depending on the whims of the sensor.

Fixed point
The 4 bit unsigned representation contains an implied binary point just after the last digit. We can move the binary point to the left one and get the numbers 0.0 through 7.5 by 0.5 increments. We can move it to the left two and get 0.0 through 3.75 by 0.25 increments.
0 0 0 4 01 0 0 0 10.5 1 0 0 14.5 0 0 0 0 0 1 0 5 11 0 0 1 11.5 1 0 1 15.5 0 1 0 0 21 1 0 0 6 0 0 1 0
www.oualline.com/practical.programmer/numbers.html 3/4

2/1/13

Numbers

0 1 0 12.5 1 1 0 16.5 1 1 0 7 31 0 1 1 13.5 1 1 1 17.5 0 1 1 0

And with a fixed binary point at the second position:


0 0 0 2 01 0 0 0 10.25 1 0 0 12.25 0 0 1 0 0.5 1 0 1 0 2.5 0 0 0 0 0 0 1 10.75 1 0 1 12.75 1 0 0 3 11 0 1 0 11.25 1 1 0 13.25 0 1 0 0 1 1 0 3.5 1.5 1 0 1 1 11.75 1 1 1 13.75 0 1 1 0

Floating point
We have enough bits for a sign, exponent and fraction. We could make floating point numbers out of our bit patterns. I think it would interesting to try because almost every bit pattern involves a boundary condition. We'll leave that for another day.

Strange
Finally we can use a system which assigns the following values to our bit patterns: "0", "1", "83", "47", "a fish", "a horse", "a cow", and "Tuesday". Some of you might look at this and think it's strange. Others may look at and think this author is strange. How do you get such a set of values? The answer is simple, I made it up. Ultimately the assignment of meaning to bit patterns is up to the programmer. True some common systems like unsigned binary make life a lot easy for him, but ultimately he can choose any assignment he wants to.

www.oualline.com/practical.programmer/numbers.html

4/4

You might also like