Analog and Digital Conversion/Signed and Unsigned Quantities
Binary Number Representation
editAny number can be represented using only "bits" (the digits 0 and 1); for example, the binary number 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
editUnsigned 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.
Signed Numbers
editTo represent negative numbers, we need to implement signed numbers. There are two general schemes for representing signed numbers: sign–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–Magnitude
editSign–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.
Two's Complement
editThe digital logic required to implement two's complement is significantly more simple to implement than a sign–magnitude representation. Therefore, 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
Questions
edit- 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.
Floating-Point Numbers
editAn 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.
Further reading
edit- Digital Circuits/Representations has the details on two's complement
- Floating Point has the details on floating-point numbers.