Analog and Digital Conversion/Signed and Unsigned Quantities

From testwiki
Jump to navigation Jump to search

Template:ADC Page

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.

1×23+1×22+0×21+1×20=thirteen

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

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.

Signed 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.

two's complement

For reasons we will discuss in another book, the digital logic required to implement two's complement is a few pennies cheaper than the digital logic required to implement sign-magnitude representation. So most computers store values in two's complement format.

Two's compliment numbers follow these rules:

  1. Half the numbers are positive, from 0 to (N/2)-1, where N is the number of expressable values (including zero) that are possible with the number of bits. If we have n bits, this value is:
    N=2n
  2. 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

Hold on a second!" you may cry. Didn't you just finish telling me a few pages ago that 1101 means thirteen?

Yes.

But now you're telling me it means -3.

Yes.

Floating-Point Numbers

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.

further reading