Вы находитесь на странице: 1из 13

CHAPTER 2

2 NUMBER SYSTEM FOR COMPUTING


2.1 CONVERSION OF DIFFERENT NUMBER SYSTEMS:
2.1.1 DECIMAL TO OTHER BASE SYSTEM
Follow the following steps from decimal to other base systems:

1. Divide the decimal number to be converted by the value of the new base.
2. Get the remainder from Step 1 as the rightmost digit (least significant digit) of new base
number.
3. Divide the quotient of the previous divide by the new base.
4. Record the remainder from Step 3 as the next digit (to the left) of the new base number.
5. Repeat Steps 3 and 4, getting remainders from right to left, until the quotient becomes zero
in Step 3.
6. The last remainder thus obtained will be the Most Significant Digit (MSD) of the new base
number.

Example −

Decimal Number: 2910

Calculating Binary Equivalent −

Step Operation Result Remainder


Step 1 29 / 2 14 1
Step 2 14 / 2 7 0
Step 3 7 / 2 3 1
Step 4 3 / 2 1 1
Step 5 1 / 2 0 1
As mentioned in Steps 2 and 4, the remainders have to be arranged in the reverse order so that the
first remainder becomes the Least Significant Digit (LSD) and the last remainder becomes the
Most Significant Digit (MSD).

Decimal Number − 2910 = Binary Number − 111012 .

2.1.2 OTHER BASE SYSTEM TO DECIMAL SYSTEM


Follow the following steps from any base to decimal base systems:

1. Determine the column (positional) value of each digit (this depends on the position of the
digit and the base of the number system).
2. Multiply the obtained column values (in Step 1) by the digits in the corresponding columns.
3. Sum the products calculated in Step 2. The total is the equivalent value in decimal.
Chapter 2

Example

Binary Number − 111012

Calculating Decimal Equivalent −

Step Binary Number Decimal Number


Step 1 111012 ((1 × 24 ) + (1 × 23 ) + (1 × 22 ) + (0 × 21 ) + (1 × 20 ))10
Step 2 111012 (16 + 8 + 4 + 0 + 1)10
Step 3 111012 2910
Binary Number − 111012 = Decimal Number − 2910

2.2 BINARY THEORY


Computing is about giving instructions to computer. Number system that the machine understand
is the binary number system and it is the basis of computing. Binary is a base-2 number system
that uses two mutually exclusive states to represent information. A binary number is made up of
elements called bits where each bit can be in one of the two possible states. Generally, we represent
them with the numerals 1 and 0. We also talk about them being true and false. Electrically, the two
states might be represented by high and low voltages or some form of switch turned on or off. We
build binary numbers the same way we build numbers in our traditional base 10 system.

You may be wondering how a simple number is the basis of all the amazing things a computer can
do. Believe it or not, it is! The processor in your computer has a complex but ultimately limited
set of instructions it can perform on values such as addition, multiplication, etc. Essentially, each
of these instructions is assigned a number so that an entire program (add this to that, multiply by
that, divide by this and so on) can be represented by a just a stream of numbers. For example, if
the processor knows operation 2 is addition, then 252 could mean "add 5 and 2 and store the output
somewhere". The reality is of course much more complicated that we will study in later lectures
but, in a nutshell, this is what a computer is.

In the days of punch-cards, one could see with their eyes the one's and zero's that make up the
program stream by looking at the holes present on the card. Of course this moved to being stored
via the polarity of small magnetic particles rather quickly (tapes, disks) and onto the point today
that we can carry unimaginable amounts of data in our pocket.

Translating these numbers to something useful to humans is what makes a computer so useful. For
example, screens are made up of millions of discrete pixels, each too small for the human eye to
distinguish but combining to make a complete image. Generally each pixel has a certain red, green
and blue component that makes up it's display color. Of course, these values can be represented
by numbers, which of course can be represented by binary! Thus any image can be broken up into

Computing Fundamentals 2 Samyan Wahla


Chapter 2

millions of individual dots, each dot represented by a tuple of three values representing the red,
green and blue values for the pixel. Thus given a long string of such numbers, formatted correctly,
the video hardware in your computer can convert those numbers to electrical signals to turn on and
off individual pixels and hence display an image.

In the binary System, instead of a one's column, a 10's column, a 100's column (and so on) we
have a one's column, a two's columns, a four's column, an eight's column, and so on, as illustrated
below.ble 2.1. Binary

2... 26 25 24 23 22 21 20
... 64 32 16 8 4 2 1

For example, to represent the number 203 in base 10, we know we place a 3 in the 1's column, a 0
in the 10'scolumn and a 2 in the 100's column. This is expressed with exponents in the table below.
Table 2.2. 203 in base 10

102 101 100


2 0 3

Or, in other words, 2 × 102 + 3 × 100 = 200 + 3 = 203. To represent the same thing in binary, we
would have the following table.

27 2 6 25 2 4 23 22 2 1 2 0
1 1 0 0 1 0 1 1

That equates to 27 + 26 + 23 +21 + 20 = 128 + 64 + 8 + 2 + 1 = 203.

When working with any kind of digital electronics in which numbers are being represented, it is
important to understand the different ways numbers are represented in these systems. Almost
without fail, numbers are represented by two voltage levels which can represent a one or a zero
(an interesting exception to this rule is the new memory device recently announced by Intel which
uses one of four possible voltage levels, thereby increasing the amount of information that can be
stored in a given space). The number system based on ones and zeroes is called the binary system
(because there are only two possible digits). Before discussing the binary system, a review of the
decimal (ten possible digits) system is in order, because many of the concepts of the binary system
will be easier to understand when introduced alongside their decimal counterpart. You should all
have some familiarity with the decimal system. For instance, to represent the positive integer one
hundred and twenty-five as a decimal number, we can write (with the positive sign implied). The
subscript 10 denotes the number as a base 10 (decimal) number. 12510 = 1*100 + 2*10 + 5*1 =

Computing Fundamentals 3 Samyan Wahla


Chapter 2

1*102 + 2*101 + 5*100 the rightmost digit is multiplied by 100, the next digit to the left is
multiplied by 101, and so on. Each digit to the left has a multiplier that is 10 times the previous
digit. Hopefully this is all a review. Some observations: To multiply a number by 10 you can
simply shift it to the left by one digit, and fill in the rightmost digit with a 0 (moving the decimal
place one to the right). To divide a number by 10, simply shift the number to the right by one digit
(moving the decimal place one to the left). To see how many digits a number needs, you can simply
take the logarithm (base 10) of the absolute value of the number, and add 1 to it. The integer part
of the result is the number of digits. For instance, log 10(33) + 1 = 2.5. The integer part of that is
2, so 2 digits are needed. With n digits, 10n unique numbers (from 0 to 10n-1) can be represented.
If n=3, 1000 (=103 ) numbers can be represented 0-999. Negative numbers are handled easily by
simply putting a minus sign (-) in front of the number. This does lead, however, to the somewhat
awkward situation where 0=-0. We will avoid this situation with binary representations, but with
a little bit of effort.

Representing fractions is a simple extension of this idea. To wit, 25.4310 = 2*10 + 5*1 + 4*0.1 +
3*0.01 = 2*101 + 5*100 + 4*10-1+ 3*10-2 The only pertinent observations here are: If there are
m digits to the right of the decimal point, the smallest number that can be represented is 10-m. For
instance if m=4, the smallest number that can be represented is 0.0001=10-4 .

2.3 BINARY REPRESENTATION OF POSITIVE I NTEGERS


Binary representations of positive can be understood in the same way as their decimal counterparts.
For example

8610 = 1*64 + 0*32 + 1*16 + 0*8 + 1*4 + 1*2 + 0*1

or

8610 = 1* 26 + 0* 25 + 1* 24 + 0* 23 + 1* 22 + 1* 21 + 0* 20

or

8610 = 10101102

The subscript 2 denotes a binary number. Each digit in a binary number is called a bit. The number
1010110 is represented by 7 bits. Any number can be broken down this way, by finding all of the
powers of 2 that add up to the number in question (in this case 26 , 24 , 22 and 21 ). You can see this
is exactly analogous to the decimal deconstruction of the number 125 that was done earlier.
Likewise we can make a similar set of observations: To multiply a number by 2 you can simply
shift it to the left by one digit, and fill in the rightmost digit with a 0. To divide a number by 2,
simply shift the number to the right by one digit. To see how many digits a number needs, you can
simply take the logarithm (base 2) of the number, and add 1 to it. The integer part of the result is
the number of digits. For instance, log2 (86) + 1 = 7.426. The integer part of that is 7, so 7 digits

Computing Fundamentals 4 Samyan Wahla


Chapter 2

are needed. With n digits, 2n unique numbers (from 0 to 2n-1) can be represented. If n=8, 256
(=28) numbers can be represented 0-255.

2.4 BITS GROUPING


It is often convenient to handle groups of bits, rather than individually. The most common grouping
is 8 bits, which forms a byte. A single byte can represent 256 (28 ) numbers. Memory capacity is
usually referred to in bytes. Two bytes is usually called a word, or short word (though word-length
depends on the application). A two-byte word is also the size that is usually used to represent
integers in programming languages. A long word is usually twice as long as a word. A less
common unit is the nibble which is 4 bits, or half of a byte. It is cumbersome for humans to deal
with writing, reading and remembering individual bits, because it takes many of them to represent
even fairly small numbers. A number of different ways have been developed to make the handling
of binary data easier for us. The most common is hexadecimal. In hexadecimal notation, 4 bits (a
nibble) are represented by a single digit. There is obviously a problem with this since 4 bits gives
16 possible combinations, and there are only 10 unique decimal digits, 0 to 9. This is solved by
using the first 6 letters (A..F) of the alphabet as numbers. The table shows the relationship between
decimal, hexadecimal and binary.

Decimal Hexadecimal Binary


0 0 0000
1 1 0001
2 2 0010
3 3 0011
4 4 0100
5 5 0101
6 6 0110
7 7 0111
8 8 1000
9 9 1001
10 A 1010
11 B 1011
12 C 1100
13 D 1101
14 E 1110
15 F 1111
There are some significant advantages to using hexadecimal when dealing with electronic
representations of numbers (if people had 16 fingers, we wouldn't be saddled with the awkward
decimal system). Using hexadecimal makes it very easy to convert back and forth from binary
because each hexadecimal digit corresponds to exactly 4 bits (log2 (16) = 4) and each byte is two
hexadecimal digit. In contrast, a decimal digit corresponds to log2 (10) = 3.322 bits and a byte
is2.408 decimal digits. Clearly hexadecimal is better suited to the task of representing binary
numbers than is decimal. As an example, the number

Computing Fundamentals 5 Samyan Wahla


Chapter 2

CA316 = 1100 1010 00112 (11002 = C16 , 10102 = A16 , 00112 = 316 ).

It is convenient to write the binary number with spaces after every fourth bit to make it easier to
read. Converting back and forth to decimal is more difficult, but can be done in the same way as
before.

323510 = C16 *256 + A16 *16 + 316 *1 = C16 *162 + A16 *161 + 316 *160

or

323510 = 12*256 + 10*16 + 3*1 = 12*162 +10*161 +3*160

Octal notation is yet another compact method for writing binary numbers. There are 8 octal
characters, 0...7. Obviously this can be represented by exactly 3 bits. Two octal digits can represent
numbers up to 64, and three octal digits up to 512. A byte requires 2.667 octal digits. Octal used
to be quiet common, it was the primary way of doing low level I/O on some old DEC computers.
It is much less common today but is still used occasionally (e.g., to set read, write and execute
permissions on UNIX systems) In summary: bit a single binary digit, either zero or one. byte 8
bits, can represent positive numbers from 0 to 255. Hexadecimal A representation of 4 bits by a
single digit 0..9,A..F. In this way a byte can be represented by two hexadecimal digits long word
A long word is usually twice as long as a word. Nibble 4 bits, half of a byte. Octal A representation
of 3 bits by a single digit 0..7. This is used much less commonly than it once was (early DEC
computers used octal for much of their I/O) word Usually 16 bits, or two bytes. But a word can be
almost any size, depending on the application being considered -- 32 and 64 bits are common sizes

2.5 SIGNED BINARY I NTEGERS


It was noted previously that we will not be using a minus sign (-) to represent negative numbers.
We would like to represent our binary numbers with only two symbols, 0 and 1. There are a few
ways to represent negative binary numbers. The simplest of these methods is called ones
complement, where the sign of a binary number is changed by simply toggling each bit (0's become
1's and vice versa). This has some difficulties, among them the fact that zero can be represented in
two different ways (for an eight bit number these would be 0000 0000 and 1111 1111)., we will
use a method called two's complement notation which avoids the pitfalls of one's complement, but
which is a bit more complicated. To represent an n bit signed binary number the leftmost bit, has
a special significance. The difference between a signed and an unsigned number is given in the
table below for an 8 bit number.

The value of bits in signed and unsigned binary numbers

Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0


Unsigned 27 26 25 24 23 22 21 20
Signed -(2 ) 26
7 2 5 2 4 2 3 2 2 21 20

Computing Fundamentals 6 Samyan Wahla


Chapter 2

Let's look at how this changes the value of some binary numbers

Binary Unsigned Signed


00100011 35 35
10100011 163 -93
11111111 255 -1
10000000 128 -128

If Bit 7 is not set (as in the first example) the representation of signed and unsigned numbers is the
same. However, when Bit 7 is set, the number is always negative. For this reason Bit 7 is sometimes
called the sign bit. Signed numbers are added in the same way as unsigned numbers, the only
difference is in the way they are interpreted. This is important for designers of arithmetic circuitr y
because it means that numbers can be added by the same circuitry regardless of whether or not
they are signed. To form a two's complement number that is negative you simply take the
corresponding positive number, invert all the bits, and add 1. The example below illustrated this
by forming the number negative 35 as a two's complement integer: 3510 = 0010 00112

invert  1101 11002

add 1  1101 11012

So 1101 1101 is our two's complement representation of -35. We can check this by adding up the
contributions from the individual bits 1101 11012 = -128 + 64 + 0 + 16 + 8 + 4 + 0 + 1 = -35.

The same procedure (invert and add 1) is used to convert the negative number to its positive
equivalent. If we want to know what what number is represented by 1111 1101, we apply the
procedure again for the binary number 1111 1101

invert  0000 0010

add 1  0000 00112

Since 0000 0011 represents the number 3, we know that 1111 1101 represents the number -3.

Note that a number can be extended from 4 bits to 8 bits by simply repeating the leftmost bit 4
times. Consider the following examples

Decimal 4 bit 8 bit


3 0011 00000011
-3 1101 11111101
7 0111 00000111
-5 1011 11111011

Computing Fundamentals 7 Samyan Wahla


Chapter 2

Let's carefully consider the last case which uses the number -5. As a 4 bit number this is represented
as 1011 = -8 + 2 + 1 = -5 The 8 bit number is 1111 1011 = -128 + 64 + 32 + 16 + 8 + 2 + 1 = -5.
It is clear that in the second case the sum of the contributions from the leftmost 5 bits (-128 + 64
+ 32 + 16 + 8 = -8) is the same as the contribution from the leftmost bit in the 4 bit representation
(-8) This process is referred to as sign extension, and can be applied whenever a number is to be
represented by a larger number of bits. In the 320C50 Digital Signal Processor, this typically
occurs when moving a number from a 16 bit register to a 32 bit register. Whether or not sign
extension is applied during such a move is determined by the sign extension mode bit. Note that
to store a 32 bit number in 16 bits you can simply truncate the upper 16 bits (as long as they are
all the same as the left-most bit in the resulting 16 bit number - i.e., the sign doesn't change). Most
processors even have two separate instructions for shifting numbers to the right (which, you will
recall, is equivalent to dividing the number in half). The first instruction is something like
LSR(Logical Shift Right) which simply shifts the bits to the right and usually fills a zero in as the
leftmost bit. The second instruction is something like ASR (Arithmetic Shift Right), which shifts
all of the bits to the right, while keeping the leftmost bit unchanged. With ASR 1010 (-6) becomes
1101 (-3). Of course, there is only one instruction for a left shift (since LSL is equivalent to ASL).
Positive binary fractions. The representation of unsigned binary fractions proceeds in exactly the
same way as decimal fractions. For example

0.62510 = 1*0.5 + 0*0.25 + 1*0.125 = 1* 2-1 + 0* 2-2 + 1* 2-3 = 0.1012 .

Each place to the right of the decimal point represents a negative power of 2, just as for decimals
they represent a negative power of 10. Likewise, if there are m bits to the right of a decimal, the
precision of the number is 2-m (versus 10-m for decimal). Though it is possible to represent numbers
greater than one by having digits to the left of the decimal place we will restrict ourselves to
numbers less than one. These are commonly used by Digital Signal Processors. The largest number
that can be represented by such a representation is 1-2-m , the smallest number is 2-m. For a fraction
with 15 bits of resolution this gives a range of approximately 0.99997 to 3.05E-5. Note that this
representations easily extended to represent all positive numbers by having the digits to the left of
the decimal point represent the integer part, and the digits to the right representing the fractiona l
part. Thus 6.62510 = 110.1012

2.6 SIGNED BINARY FRACTIONS


Signed binary fractions are formed much like signed integers. We will work with a single digit to
the left of the decimal point, and this will represent the number -1 = -20 . The rest of the
representation of the fraction remains unchanged. Therefore this leftmost bit represents a sign bit
just as with two's complement integers. If this bit is set, the number is negative, otherwise the
number is positive. The largest positive number that can be represented is still 1-2-m but the largest
negative number is -1. The resolution is still 1-2-m. There is a terminology for naming the resolutio n
of signed fractions. If there are m bits to the right of the decimal point, the number is said to be in

Computing Fundamentals 8 Samyan Wahla


Chapter 2

Qm format. For a 16 bit number (15 bits to the right of the decimal point) this results in Q15
notation.

Signed binary fractions are easily extended to include all numbers by representing the number to
the left of the decimal point as a 2's complement integer, and the number to the right of the decimal
point as a positive fraction. Thus -6.62510 = (-7+0.375)10 = 1001.0112 Note, that as with two's
complement integers, the leftmost digit can be repeated any number of times without affecting the
value of the number. A Quicker Method for Converting Binary Fractions. Another way to convert
Qm numbers to decimal is to represent the binary number as a signed integer, and to divide by 2m.
To convert a decimal number to Qm, multiply the number by 2m and take the rightmost m digits.
Note, this simply truncates the number; it is more elegant, and accurate, but slightly more
complicated, to round the number. Examples (all Q7 numbers):

 Convert 0.100 1001 to decimal.


Take the binary number 0100 1001 (=7310), and divide by 27=128. The answer is
73/128=0.5703125, which agrees with the result of the previous exercise (Positive Binary
Fractions).
 Convert 1.100 1001 to decimal.
Take the two's complements binary number 1100 1001 (=-5510), and divide by 128. The
answer is -0.4296875, which agrees with the result of the previous exercise (Signed Binary
Fractions).
 Convert 0.9 to Q7 format
Multiply 0.9 by 128 to get 115.2. This is represented in binary as 111 0011, so the Q7
representation is 0.111 0011. This agrees with the result of the previous exercise (Positive
Binary Fractions).
 Convert -0.9 to Q7 format
Multiply -0.9 by 128 to get -115.2. The Q7 representation is 1.000 1101. This agrees with
the result of the previous exercise (Signed Binary Fractions).

2.7 ADDITION
2.7.1 Adding unsigned numbERS

Adding unsigned numbers in binary is quite easy. Recall that with 4 bit numbers we can represent
numbers from 0 to 15. Addition is done exactly like adding decimal numbers, except that you have
only two digits (0 and 1). The only number facts to remember are that

0+0 = 0, with no carry,


1+0 = 1, with no carry,
0+1 = 1, with no carry,
1+1 = 0, and you carry a 1.

Computing Fundamentals 9 Samyan Wahla


Chapter 2

so to add the numbers 0610 =01102 and 0710 =01112 (answer=1310 =11012 ) we can write out the
calculation (the results of any carry is shown along the top row, in italics).

Unsigned
Decimal
Binary
1 (carry) 110 (carry)
06 0110
+07 +0111
13 1101

The only difficulty adding unsigned numbers occurs when you add numbers that are too large.
Consider 13+5.

Decimal Unsigned Binary


0 (carry) 1101 (carry)
13 1101
+05 +0101
18 10010

The result is a 5 bit number. So the carry bit from adding the two most significant bits represents
a results that overflows (because the sum is too big to be represented with the same number of bits
as the two addends).

2.7.2 ADDING SIGNED NUMBERS

Adding signed numbers is not significantly different from adding unsigned numbers. Recall that
signed 4 bit numbers (2's complement) can represent numbers between -8 and 7. To see how this
addition works, consider three examples.

Decimal Signed Binary


1110 (carry)
-2 1110
+3 +0011
1 0001

Decimal Signed Binary


011 (carry)
-5 1011
+3 +0011
-2 1110

Decimal Signed Binary


1100 (carry)
-4 1100
-3 +1101
-7 1001

Computing Fundamentals 10 Samyan Wahla


Chapter 2

In this case the extra carry from the most significant bit has no meaning. With signed numbers
there are two ways to get an overflow -- if the result is greater than 7, or less than -8. Let's consider
these occurrences now.

Decimal Signed Binary


110 (carry)
6 0110
+3 +0011
9 1001

Decimal Signed Binary


1001 (carry)
-7 1001
-3 +1101
-10 0110

Obviously both of these results are incorrect, but in this case overflow is harder to detect. But you
can see that if two numbers with the same sign (either positive or negative) are added and the result
has the opposite sign, an overflow has occurred.

2.7.3 ADDING FRACTIONS

There is no further difficult in adding two signed fractions, only the interpretation of the results
differs. For instance consider addition of two Q3 numbers shown (compare to the example with
two 4 bit signed numbers, above).

Decimal Fractional Binary


1110 (carry)
-0.25 1110
+0.375 +0011
0.125 0001

Decimal Fractional Binary


011 (carry)
-0.625 1011
+0.375 +0011
-0.25 1110

Decimal Fractional Binary


1100 (carry)
-0.5 1100
-0.375 +1101
-0.875 1001

If you look carefully at these examples, you'll see that the binary representation and calculatio ns
are the same as before, only the decimal representation has changed. This is very useful because it
means we can use the same circuitry for addition, regardless of the interpretation of the results.

Computing Fundamentals 11 Samyan Wahla


Chapter 2

Even the generation of overflows resulting in error conditions remains unchanged (again compare
with above)

Decimal Fractional Binary


110 (carry)
0.75 0110
+0.375 +0011
1.125 1001

Decimal Fractional Binary


1001 (carry)
-0.875 1001
-0.375 +1101
-1.25 0110

2.8 MULTIPLICATION
2.8.1 MULTIPLYING UNSIGNED NUMBERS

Multiplying unsigned numbers in binary is quite easy. Recall that with 4 bit numbers we can
represent numbers from 0 to 15. Multiplication can be performed done exactly as with decimal
numbers, except that you have only two digits (0 and 1). The only number facts to remember are
that 0*1=0, and 1*1=1 (this is the same as a logical "and").

Multiplication is different than addition in that multiplication of an n bit number by an m bit


number results in an n+m bit number. Let's take a look at an example where n=m=4 and the result
is 8 bits

Decimal Binary
1010
x0110
0000
10
1010
x6
1010
60
+0000
0111100

In this case the result was 7 bit, which can be extended to 8 bits by adding a 0 at the left. When
multiplying larger numbers, the result will be 8 bits, with the leftmost set to 1, as shown.

Decimal Binary
1101
13
x1110
x14
0000
182
1101

Computing Fundamentals 12 Samyan Wahla


Chapter 2

1101
+1101
10110110

As long as there are n+m bits for the result, there is no chance of overflow. For 2 four bit
multiplicands, the largest possible product is 15*15=225, which can be represented in 8 bits.

2.8.2 MULTIPLYING SIGNED NUMBERS

There are many methods to multiply 2's complement numbers. The easiest is to simply find the
magnitude of the two multiplicands, multiply these together, and then use the original sign bits to
determine the sign of the result. If the multiplicands had the same sign, the result must be positive,
if the they had different signs, the result is negative. Multiplication by zero is a special case (the
result is always zero, with no sign bit).

2.8.3 MULTIPLYING FRACTIONS

As you might expect, the multiplication of fractions can be done in the same way as the
multiplication of signed numbers. The magnitudes of the two multiplicands are multiplied, and the
sign of the result is determined by the signs of the two multiplicands.

There are a couple of complications involved in using fractions. Although it is almost impossib le
to get an overflow (since the multiplicands and results usually have magnitude less than one), it is
possible to get an overflow by multiplying -1x-1 since the result of this is +1, which cannot be
represented by fixed point numbers.

The other difficulty is that multiplying two Q3 numbers, obviously results in a Q6 number, but we
have 8 bits in our result (since we are multiplying two 4 bit numbers). This means that we end up
with two bits to the left of the decimal point. These are sign extended, so that for positive numbers
they are both zero, and for negative numbers they are both one. Consider the case of multiplying -
1/2 by -1/2 (using the method from the textbook):

Decimal Fractional Binary


1100
x0100
0000
-0.5
0000
x0.5
+111100
-0.25
11110000

This obviously presents a difficulty if we wanted to store the number in a Q3 result, because if we
took just the 4 leftmost bits, we would end up with two sign bits. So what we'd like to do is shift
the number to the left by one and then take the 4 leftmost bit. This leaves us with 1110 which is
equal to -1/4, as expected.

Computing Fundamentals 13 Samyan Wahla

Вам также может понравиться