# Signed 16 bit numbers in AD21161 and VisualDSP

Started by April 30, 2007
Hello.

First I would like to say that I have ask this question again some days ago, I am not sure if it is posted somewhere though. I am searching and cannot find it, I had done some things wrong with my registration so perhaps it has not been posted. So, if someone is disturbed, I am apologizing.

My problem is that in the VisualDSP compiler all numbers are represented in 32 bit format, a signed short is 32 bits. That is a problem in my code because if I want to represent a negative number, it will not be in the two's complement until it reaches the 32 bit width, for example: the number 0xEAFF is -5377 if represented as a 16 bit signed int but is 60159 if represented as a 32 bit signed int.

How will I manipulate the numbers I got from the SPORTS if they are negative numbers?

What could I do here? Make the calculations in software for two' complement? Won't this subtract computation power?

I am pretty confused.

My best regards, Bill.

P.S. I posted the same msg in comp.dsp, I really don't understand what is the difference in both, please let me know.
On Mon, 30 Apr 2007 v...@intracomdefense.com wrote:

> My problem is that in the VisualDSP compiler all numbers are
>represented in 32 bit format, a signed short is 32 bits. That is a
>problem in my code because if I want to represent a negative number, it
>will not be in the two's complement until it reaches the 32 bit width,
>for example: the number 0xEAFF is -5377 if represented as a 16 bit signed
>int but is 60159 if represented as a 32 bit signed int.
>
> How will I manipulate the numbers I got from the SPORTS if they are negative numbers?

Look at the FEXT Rx by Ry (SE) instruction. It can do the job for you
because the result is sign extended out to 32 bits.
> P.S. I posted the same msg in comp.dsp, I really don't understand what
>is the difference in both, please let me know.

This one is on yahoo, comp.dsp is general usenet and gets copied on
servers all over the world. Comp.dsp is more general too, this is pretty
much aimed at ADI dsp's. I haven't had time to play on comp.dsp, kinda
miss it...

Patience, persistence, truth,
Dr. mike