Re: Signed 16 bit numbers in AD21161 and VisualDSP
- From: Jim Thomas <jthomas@xxxxxxxxxxxx>
- Date: Mon, 30 Apr 2007 09:26:52 -0400
kostbill 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?
You can either convert them to 32-bit numbers by shifting them left by 16 bits, or you can sign extend them. That is:
x = x << 16
or
if (x&0x8000) {x = x | 0xffff0000}
The first approach converts the number from 1.15 fractional format to 1.31. The second converts from 16-bit integer to 32-bit integer.
You might also experiment with short-space addressing. If your number is in internal memory (which I assume it is, since sport dmas go to internal memory IIRC), you can read the lower 16 bits (ignoring the upper 16) by reading from addr*2. You can read the upper by reading from addr*2+1. I might have upper and lower reversed here, but I'm pretty sure that reading from short-space will sign-extend the result. That's why I said "experiment with."
--
Jim Thomas Principal Applications Engineer Bittware, Inc
jthomas@xxxxxxxxxxxx http://www.bittware.com (603) 226-0404 x536
Never ascribe to malice that which is adequately explained by incompetence. -
Napoleon Bonaparte
.
- References:
- Signed 16 bit numbers in AD21161 and VisualDSP
- From: kostbill
- Signed 16 bit numbers in AD21161 and VisualDSP
- Prev by Date: Digiatal Sampling correction Interpolation/Decimation in e OFDM Modem
- Next by Date: Re: Packages for ORCAD
- Previous by thread: Signed 16 bit numbers in AD21161 and VisualDSP
- Next by thread: Digiatal Sampling correction Interpolation/Decimation in e OFDM Modem
- Index(es):
Relevant Pages
|