Analog and Digital Conversion/Signed and Unsigned Quantities
Binary Number Representation
Any number can be represented using only "bits", the digits 0 and 1 -- for example, the 1101 represents thirteen. These bits, ordered in sequence, represent ascending powers of two.
The bit on the right is called the "Least Significant Bit" (LSB) because it represents 1, the lowest power of 2, and the bit on the left is called the "Most Significant Bit" (MSB) because it represents the highest power of two.
Unsigned numbers are represented in a straightforward manner, with the LSB on the right, and the MSB on the left. Unsigned numbers are always positive (or zero), because they don't have a sign for denoting negative numbers.
To represent negative numbers, we need to implement signed numbers. there are two general schemes for representing signed numbers: Sign and Magnitude, or Two's Compliment. There are other schemes as well, such as one's compliment, but we won't discuss them here. For more information on the subject, see the relevant sections of Digital Circuits.
Sign and Magnitude
Sign and Magnitude numbers are the same as unsigned numbers, except with the addition of a "sign bit". If the sign bit is 0, the number is positive. If the sign bit is 1, the number is negative.
The digital logic required to implement two's complement is significantly more simple to implement then a sign-magnitude representation. So most computers store values in two's complement format. Two's compliment numbers follow these rules:
- Half the numbers are positive, from 0 to (N/2)-1, where N is the number of expressible values (including zero) that are possible with the number of bits. If we have n bits, this value is:
- Negative numbers are obtained by inverting the bits in the positive number, and then adding 1 to it.
For instance, If we have the number 5 (0101) in a four-bit Two's Compliment number, we can get the representation for -5 by inverting the number (1010), and adding 1 to it (1011).
To get the positive value of a negative number, we reverse the process.
For example, the 4 bit signed numbers (3 data bits + 1 sign bit) are:
0111 = +7 0110 = +6 0101 = +5 0100 = +4 0011 = +3 0010 = +2 0001 = +1 0000 = +0 1111 = -1 1110 = -2 1101 = -3 1100 = -4 1011 = -5 1010 = -6 1001 = -7 1000 = -8
- Q) Didn't you just finish telling me a few pages ago that 1101 means thirteen?
Yes. It could also be a lot of other things too. The bits 1101 form a bit pattern that can be interpreted to mean anything. When we're talking about unsigned arithmetic, 1101 is "13" in decimal numbers. When we're talking about signed arithmetic, 1101 might mean -3 if we're doing 4-bit signed arithmetic.
- In 16-bit signed arithmetic, 1101 is 13
- In sign+magnitude representation, 1101 is -5.
- In one's compliment, 1101 is -4
- It's important to note that a single bit pattern might have different meanings depending on how you interpret it. Keeping the interpretation straight is therefore very important.
An additional type of binary numbers are called "Floating Point" numbers. These numbers allow fractional quantities to be expressed using bits. Floating-point numbers are beyond the scope of this book, but keep in mind that some samplers output values in floating point format.