CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

2's Complement Bit toggle
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








PostPosted: Sun Mar 08, 2009 1:37 pm     Reply with quote

Thanks again! I'm gonna connect the circuit this week and test your answers out. I will post again then. Very Happy
Guest








PostPosted: Fri Mar 13, 2009 10:57 am     Reply with quote

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

Very Happy Very Happy

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

View user's profile Send private message

PostPosted: Fri Mar 13, 2009 1:18 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Mar 13, 2009 3:00 pm     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group