D. Binary Number Formats

In digital signal processing, there are many ways to represent numerical data in computing hardware. These representations, called binary number formats, each have their own advantages and shortcomings. The simpler number formats enable us to use uncomplicated hardware designs at the expense of a restricted range of number representation and susceptibility to arithmetic errors. The more elaborate number formats are somewhat difficult to implement in hardware, but they allow us to manipulate very large and very small numbers while providing immunity to many numerical precision problems associated with binary arithmetic. The number format chosen for any given application can mean the difference between processing success and failure—it’s where our digital signal processing rubber meets the road.

In this appendix, we’ll describe the most common types of binary number formats, and show why and when they’re used.

Unsigned Binary Number Format

In Chapter 9, we introduced binary numbers and provided the following table to show how sequences of binary digits (0 and 1) could be used to represent decimal numbers.

The number of bits in a binary number is known as its word length—hence 1101 has a word length of four, with the leftmost bit known as the most significant bit (msb), while the rightmost bit is called the least significant bit (lsb).

The binary numbers in Table D.1 are called unsigned binary numbers because in their current form, they can only represent positive decimal numbers. For binary numbers to be at all useful in practice, they must be able to represent negative decimal values. There are a number of different ways to represent both positive and negative decimal numbers in binary form and here we present the most popular ways to do so.

Image

Table D.1 First 16 Binary Numbers

Sign-Magnitude Binary Number Format

We can use binary numbers to represent negative decimal numbers by dedicating one of the bits in a binary word to indicate the sign of a number. Let’s consider a popular binary number format known as sign-magnitude. Here, we assume that a binary word’s leftmost bit is a sign bit and the remaining bits represent the magnitude of a number that is always positive. For example, we can say that the 4-bit binary number 00112 is equal to +310 and the binary number 10112 is equal to –310 as shown in Figure D-1.

Image

Figure D-1 Sign-magnitude number format system using the leftmost bit to indicate positive and negative decimal numbers.

Of course, using one of the bits as a sign bit reduces the magnitude of the decimal numbers we can represent. A 4-bit unsigned binary word, for example, can represent 16 different decimal integer values, 0–1510. In the sign-magnitude binary format, a 4-bit word can only represent decimal numbers in the range of –710 to +710.

Two’s Complement Binary Number Format

Another common binary number scheme is known as the two’s complement format that also uses the leftmost bit as a sign bit. The two’s complement format is the most convenient numbering scheme from a hardware-design standpoint and has been used for decades. It enables computers to perform both addition and subtraction using the same computational hardware. To obtain the negative version of a positive two’s complement binary number, we merely complement (change a 1 bit to a 0 bit, and change a 0 bit to a 1 bit) each bit, and add 1 to the complemented word. For example, with 00112 representing a decimal 310 in two’s complement format, we obtain –310 through the steps shown in Figure D-2.

Image

Figure D-2 Obtaining the negative version of a positive two’s complement binary number.

In the two’s complement format, a 4-bit word can represent decimal numbers in the range of –810 to +710. Table D.2 shows 4-bit word examples of sign-magnitude and two’s complement binary formats.

Image

Table D.2 Examples of Binary Number Formats

While using two’s complement numbers, we have to be careful when adding two numbers that have different word lengths. Consider the case where a 4-bit number is added to an 8-bit number as presented in Figure D-3.

Image

Figure D-3 Adding two positive two’s complement numbers that have different word lengths.

No problem so far. The trouble occurs when our 4-bit number is negative. Instead of adding a +310 to the +1510, let’s try to add a –310 to the +1510 as shown in Figure D-4.

Image

Figure D-4 Incorrectly adding a positive and a negative two’s complement number that have different word lengths.

The arithmetic error above can be avoided by performing what’s called a sign-extend operation on the 4-bit number. This process, typically performed automatically in computer hardware, extends the sign bit of the 4-bit negative number to the left making it an 8-bit negative number. If we sign-extend the –310 and then perform the addition, we’ll get the correct answer as we see in Figure D-5.

Image

Figure D-5 Correctly adding a positive and a negative two’s complement number that have different word lengths.

Offset Binary Number Format

Another useful binary number scheme is known as the offset binary number format. Although this format is not as common as the two’s complement binary number format, it still shows up in some hardware. Table D.2 shows offset binary format examples for 4-bit binary words. It may interest the reader that we can convert, back and forth, between the two’s complement and offset binary formats merely by complementing (change a 1 to a 0, and change a 0 to a 1) a binary word’s most significant bit.

The history, arithmetic, and utility of the many available number formats is a very broad field of study. A thorough and very readable discussion of the subject is given in Donald E. Knuth’s The Art of Computer Programming: Seminumerical Methods, vol. 2.

Alternate Binary Number Notation

As the use of business computers in the 1960s and home computers in the 1970s rapidly expanded, computer programmers grew tired of manipulating long strings of ones and zeros on paper and began to use more convenient ways to represent binary numbers using digits other than a 1 or a 0. The two most popular notational ways to represent binary number are called octal binary number notation and hexadecimal binary number notation.

Octal Binary Number Notation

The octal binary number notation uses a base-8 number system. Converting from binary to octal is as simple as separating the binary number into 3-bit groups starting from the right. For example, the binary number 101010012 can be converted to octal format as shown in Figure D-6. In that figure, we use a subscripted 8 to signify an octal number.

Image

Figure D-6 Representing an 8-bit binary word with 3 octal digits.

The value of using octal notation is that it’s easier to write, remember, and verbalize a 3-digit octal number than an 8-digit binary number. The octal number 2518 is simply easier for programmers to work with than the binary number 101010012. Of course, the only valid digits in the octal notation are 0–7. The decimal digits 8 and 9 have no meaning in octal representation.

Hexadecimal Binary Number Notation

Another popular binary format is the hexadecimal binary number notation using 16 as its base. Converting from binary to hexadecimal is done by separating the binary number, this time, into 4-bit groups starting from the right. The binary number 101010012 is converted to hexadecimal format as shown in Figure D-7.

The peculiar aspect of hexadecimal number notation is that it uses letters to represent decimal values greater than 9. For example, the 4-bit number 10102 = 1010 in Figure D-7 is represented as A16 in hexadecimal notation. Here, we use a subscripted 16 to signify a hexadecimal number.

Image

Figure D-7 Representing an 8-bit binary word with 2 hexadecimal digits.

If you haven’t seen hexadecimal notation before, don’t let the A916 number above confuse you. In this notation, the letters A, B, C, D, E, and F represent the decimal digits 10, 11, 12, 13, 14, and 15, respectively. Table D.3 lists the permissible digit representations in the alternate octal and hexadecimal binary number notations.

Image

Table D.3 The Digits Used in Alternate Binary Number Notations

Like octal notation, the value of using hexadecimal notation is that it’s simply easier to write, remember, and verbalize a 2-digit hexadecimal number than an 8-digit binary number.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.78.102