Re: Signed 16 bit numbers in AD21161 and VisualDSP



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
.



Relevant Pages

  • Re: frustrated by fscanf and sscanf
    ... there is no threads talking about reading a series of numbers. ... <snip description of input file structure> ... Your description of the file format makes no sense at all. ... along with a sample of your input file or a clearer ...
    (comp.lang.c)
  • Re: Reading and Writing to Binary files
    ... really used it but to look up a command every once and a while if I forgot ... > only do IO in a textual format, that is what they were made for. ... > you wonder about the binary flag passed to open, you didn't bother reading ... program uses the "istringstream" class to store the information. ...
    (comp.programming)
  • Re: TCL 8.5.0.0 beta not handling XBMs?
    ... I'm not aware of any reason for XBM files to be a problem in general, ... I thought the error was saying it found something nasty reading the file. ... due to the not-very-obvious format of the -bitmap option (which in turn ...
    (comp.lang.tcl)
  • Re: Field to Upper Case
    ... All upper case is HARD TO READ. ... Form Textboxes do. ... its Properties; click the Format tab. ...
    (microsoft.public.access.gettingstarted)
  • Word should open docs with the same formatting as they were saved
    ... Word 2003 has introduced the "reading view", which is the default format when ... formatting and pagination in reading view, in some cases looking worse than ... This post is a suggestion for Microsoft, ...
    (microsoft.public.word.pagelayout)