I am trying to put a signed 16 bit number into the rightmost 16 bits
of a u32 buffer.

I have something that nearly works:

  test = (analogue_out(0) < 0 ) ?
    0x00008000 | (u32)(analogue_out(0) * scale(0) * -3276.7) :
    0x00000000 | (u32)(analogue_out(0) * scale(0) * 3276.7);

(Though, unexpectedly, for scale = 10.0 and analogue_out = 1 or -1 the
output is 0x00007FFE and 0x000FFFE respectively, which slightly
surprises me)

However, surely there must be a tidier and faster way? (probably using
s16 typecasting and a bitwise OR?

-- 
atp
"Torque wrenches are for the obedience of fools and the guidance of wise men"

------------------------------------------------------------------------------
Create and publish websites with WebMatrix
Use the most popular FREE web apps or write code yourself; 
WebMatrix provides all the features you need to develop and 
publish your website. http://p.sf.net/sfu/ms-webmatrix-sf
_______________________________________________
Emc-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/emc-developers

Reply via email to