# Two's complement and fractional arithmetic for 16-bit processors

 Page 1 / 1
Two's-complement notation is a mathematically convenient way of representing signed numbers in microprocessors. The most significant bit of a two's complement number represents its sign, and the remaining bits represent its magnitude. Fractional arithmetic allows one to multiply numbers on an integer processor without incurring overflow. Fractional arithmetic requires sign-extension of multipliers and multiplicands, and it requires the product of two numbers to be left-shifted one bit.

## Two's-complement notation

Two's-complement notation is an efficient way of representing signed numbers in microprocessors. It offers theadvantage that addition and subtraction can be done with ordinary unsigned operations. When a number is written intwo's complement notation, the most significant bit of the number represents its sign: 0 means that the number ispositive, and 1 means the number is negative. A positive number written in two's-complement notation is the same as thenumber written in unsigned notation (although the most significant bit must be zero). A negative number can bewritten in two's complement notation by inverting all of the bits of its absolute value, then adding one to the result.

Consider the following four-bit two's complement numbers (in binary form):

 $1=0001$ $-1=1110+1=1111$ $2=0010$ $-2=1101+1=1110$ $6=0110$ $-6=1001+1=1010$ $8=1000$ $-8=0111+1=1000$

$1000$ represents -8, not 8. This is because the topmost bit (the sign bit) is 1, indicating that the number isnegative.

The maximum number that can be represented with a $k$ -bit two's-complement notation is $2^{\mathrm{k-1}}-1$ , and the minimum number that can be represented is $-2^{\mathrm{k-1}}$ . The maximum integer that can be represented in a 16-bit memory register is 32767, and the minimum integer is-32768.

## Fractional arithmetic

The DSP microprocessor is a 16-bit integer processor with some extra support for fractional arithmetic. Fractional arithmetic turns out to be very useful for DSP programming, since it frees us from worries about overflow onmultiplies. (Two 16-bit numbers, multiplied together, can require 32 bits for the result. Two 16-bit fixed-pointfractional numbers also require 32 bits for the result, but the 32-bit result can be rounded into 16 bits while onlyintroducing an error of approximately $2^{-16}$ .) For this reason, we will be using fixed-point fractional representation to describe filter taps and inputs throughout this course.

Unfortunately, the assembler and debugger we are using do not recognize this fractional fixed-point representation. For thisreason, when you are using the assembler or debugger, you will see decimal values (ranging from -32768 to 32767) on screeninstead of the fraction being represented. The conversion is simple; the fractional number being represented is simply thedecimal value shown divided by 32768. This allows us to represent numbers between -1 and $1-2^{-15}$ .

1 cannot be represented exactly.

When we multiply using this representation, an extra shift left is required. Consider the two examplesbelow:

 fractional $0.5\times 0.5=0.25$ decimal $16384\times 16384=40962^{16}: 4096/327681/8$ hex $4000\times 4000=10002^{16}$
 fractional $0.125\times 0.75=0.093750$ decimal $4096\times 24576=15362^{16}: 1536/327680.046875$ hex $1000\times 6000=06002^{16}$

You may wish touse the MATLAB commands hex2dec and dec2hex . When we do the multiplication, we are primarily interested inthe top 16 bits of the result, since these are the data that are actually used when we store the result back into memoryand send it out to the digital-to-analog converter. (The entire result is actually stored in the accumulator, sorounding errors do not accumulate when we do a sequence of multiply-accumulate operations in the accumulators.) As theexample above shows, the top 16 bits of the result of multiplying the fixed point fractional numbers together ishalf the expected fractional result. The extra left shift multiplies the result by two, giving us the correct finalproduct.

The left-shift requirement can alternatively be explained by way of decimal place alignment. Remember that when wemultiply decimal numbers, we first multiply them ignoring the decimal points, then put the decimal point back in the laststep. The decimal point is placed so that the total number of digits right of the decimal point in the multiplier andmultiplicand is equal to the number of digits right of the decimal point in their product. The same applies here; the"decimal point" is to the right of the leftmost (sign) bit, and there are 15 bits (digits) to the right of this point. Sothere are a total of 30 bits to the right of the decimal in the source. But if we do not shift the result, there are 31bits to the right of the decimal in the 32-bit result. So we shift the number to the left by one bit, which effectivelyreduces the number of bits right of the decimal to 30.

Before the numbers are multiplied by the ALU, each term is sign-extended generating a 17-bit number from the 16-bit input. Because the examples presented above are allpositive, the effect of this sign extension is simply adding an extra "0" bit at the top of the register( i.e. , positive numbers are not affected by the sign extension). As the following example illustrates,not including this sign-bit for negative numbers produces erroneous results.

 fractional $-0.5\times 0.5=-0.25$ decimal $49152\times 16384=122882^{16}: 12288/326780.375$ hex $C000\times 4000=30000000=30002^{16}$

Note that even after the result is left-shifted by one bit following the multiply, the top bit of the result is still"0", implying that the result is incorrectly interpreted as a positive number.

To correct this problem, the ALU sign-extends negative multipliers and multiplicands by placing a "1" instead of a"0" in the added bit. This is called sign extension because the sign bit is "extended" to the left another place, addingan extra bit to the left of the number without changing the number's value.

 fractional $-0.5\times 0.5=-0.25$ hex $1C000\times 4000=70000000=70002^{16}$

Although the top bit of this result is still "0", after the final 1-bit left-shift the result is E000 000h which is a negative number (the top bit is "1"). To check the final answer, we can negate the product using the two'scomplement method described above. After flipping all of the bits we have 1FFF FFFFh , and adding one yields 2000 0000h , which equals 0.25 when interpreted as an 32 bit fractional number.

how do they get the third part x = (32)5/4
can someone help me with some logarithmic and exponential equations.
20/(×-6^2)
Salomon
okay, so you have 6 raised to the power of 2. what is that part of your answer
I don't understand what the A with approx sign and the boxed x mean
it think it's written 20/(X-6)^2 so it's 20 divided by X-6 squared
Salomon
I'm not sure why it wrote it the other way
Salomon
I got X =-6
Salomon
ok. so take the square root of both sides, now you have plus or minus the square root of 20= x-6
oops. ignore that.
so you not have an equal sign anywhere in the original equation?
Commplementary angles
hello
Sherica
im all ears I need to learn
Sherica
right! what he said ⤴⤴⤴
Tamia
what is a good calculator for all algebra; would a Casio fx 260 work with all algebra equations? please name the cheapest, thanks.
a perfect square v²+2v+_
kkk nice
algebra 2 Inequalities:If equation 2 = 0 it is an open set?
or infinite solutions?
Kim
The answer is neither. The function, 2 = 0 cannot exist. Hence, the function is undefined.
Al
y=10×
if |A| not equal to 0 and order of A is n prove that adj (adj A = |A|
rolling four fair dice and getting an even number an all four dice
Kristine 2*2*2=8
Differences Between Laspeyres and Paasche Indices
No. 7x -4y is simplified from 4x + (3y + 3x) -7y
is it 3×y ?
J, combine like terms 7x-4y
how do you translate this in Algebraic Expressions
Need to simplify the expresin. 3/7 (x+y)-1/7 (x-1)=
. After 3 months on a diet, Lisa had lost 12% of her original weight. She lost 21 pounds. What was Lisa's original weight?
what's the easiest and fastest way to the synthesize AgNP?
China
Cied
types of nano material
I start with an easy one. carbon nanotubes woven into a long filament like a string
Porter
many many of nanotubes
Porter
what is the k.e before it land
Yasmin
what is the function of carbon nanotubes?
Cesar
what is nanomaterials​ and their applications of sensors.
what is nano technology
what is system testing?
preparation of nanomaterial
Yes, Nanotechnology has a very fast field of applications and their is always something new to do with it...
what is system testing
what is the application of nanotechnology?
Stotaw
In this morden time nanotechnology used in many field . 1-Electronics-manufacturad IC ,RAM,MRAM,solar panel etc 2-Helth and Medical-Nanomedicine,Drug Dilivery for cancer treatment etc 3- Atomobile -MEMS, Coating on car etc. and may other field for details you can check at Google
Azam
anybody can imagine what will be happen after 100 years from now in nano tech world
Prasenjit
after 100 year this will be not nanotechnology maybe this technology name will be change . maybe aftet 100 year . we work on electron lable practically about its properties and behaviour by the different instruments
Azam
name doesn't matter , whatever it will be change... I'm taking about effect on circumstances of the microscopic world
Prasenjit
how hard could it be to apply nanotechnology against viral infections such HIV or Ebola?
Damian
silver nanoparticles could handle the job?
Damian
not now but maybe in future only AgNP maybe any other nanomaterials
Azam
can nanotechnology change the direction of the face of the world
At high concentrations (>0.01 M), the relation between absorptivity coefficient and absorbance is no longer linear. This is due to the electrostatic interactions between the quantum dots in close proximity. If the concentration of the solution is high, another effect that is seen is the scattering of light from the large number of quantum dots. This assumption only works at low concentrations of the analyte. Presence of stray light.
the Beer law works very well for dilute solutions but fails for very high concentrations. why?
how did you get the value of 2000N.What calculations are needed to arrive at it
Privacy Information Security Software Version 1.1a
Good
Got questions? Join the online conversation and get instant answers!