Thanks again! I'm gonna connect the circuit this week and test your answers out. I will post again then.
Guest
Posted: Fri Mar 13, 2009 10:57 am
Ttelmah I finally had time to try out you code and it worked nicely.
Code:
int16 val_from_unit;
signed int16 numeric_val;
numeric_val=val_from_unit & 0x1FFF; //get the thirteen numeric bits
if (val_from_unit & 0x2000) numeric_val |= 0xE000; //sign extend
One last question could you explain your second line of code? I'm not understanding what it is saying. Thanks again.
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
Posted: Fri Mar 13, 2009 1:18 pm
Without sign extension you won't get any negative number, e.g. 0x2000 is understood as 8192, but it means -8192.
Sydney
Joined: 13 Feb 2009 Posts: 71
Posted: Fri Mar 13, 2009 3:00 pm
Its because your 14 bit number say 0b11111111111111 = -1 when its put into your 16 bit var it becomes 0b0011111111111111 = 16383, so the sign bit 14 needs copying into 15 and 16 to make it -1 again
All times are GMT - 6 Hours Goto page Previous1, 2
Page 2 of 2
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum