2's complement to signed int
pgbpsu
Posts: 460
I've got a 24-bit 2's complement data sample sitting in a 32-bit register (long). I'm doing the following to get the sample written out as a signed integer. Is this correct? Can it be this simple?
I've run this and things look good, but I want to be sure that's not accidental.
Thanks,
pgb
shl sample, #8 ' move MSbit to bit 31 sar sample, #8 ' shift back down to where it belongs; preserving the sign wrlong sample, HUB_mem_ptr ' place this signed int into HUB memory for later...
I've run this and things look good, but I want to be sure that's not accidental.
Thanks,
pgb
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
As always, thanks for your help.
If there is an assembly instruction for sign extend I didn't see it. Let me know if you find one ; )
To verify that what I'm doing is working it dawned on me that I could simply feed a sine wave into my ADC to make sure I'm getting back what I should. That will verify that I'm not making any mistakes and that I handle zero crossings correctly. So, off to write some more Prop code to help me verify the prop code I've already written...
Have a great weekend.
p
Of course, this works only with 23- or 24-bit signed numbers that need extending! The MUXx instructions can also be used with an auxiliary long:
-Phil
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Just a few PropSTICK Kit bare PCBs left!