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

Bit Conversion

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
pr83



Joined: 20 Jul 2006
Posts: 15

View user's profile Send private message

Bit Conversion
PostPosted: Tue Jan 02, 2007 6:59 pm     Reply with quote

I have a 16 bit variable. How do I convert it into a 8 bit variable such that the 8 bit variable contains the bits(10,9,8,7,6,5,4,3,2) of the 16 bit variable.
Any suggestions!!
Guest








PostPosted: Tue Jan 02, 2007 7:37 pm     Reply with quote

Hi,

How about ANDing the 16 bit value with 0x03FC to strip off the lower two bits and the upper six bits, and then shift the result two places to the left?

That's something I'd try!

Tim
Ken Johnson



Joined: 23 Mar 2006
Posts: 197
Location: Lewisburg, WV

View user's profile Send private message

PostPosted: Tue Jan 02, 2007 8:33 pm     Reply with quote

Yes, logical "and", then shift, or, just shift and assign to an 8-bit variable:

x8 = y16 >> 2;

But I'm afraid you'll still have trouble stuffing 9 bits into an 8-bit variable (count 'em)

Ken
Guest








PostPosted: Wed Jan 03, 2007 11:19 am     Reply with quote

I tried manipulating 0x0F1F (16 bits) variable such that the new 8 bit variable would be 11000111. I tried to use shift_left(), but I always ended up with 0x01.
Any suggestions!!
Guest








PostPosted: Wed Jan 03, 2007 11:34 am     Reply with quote

Yes, post your code! At this point, we can't help without seeing specifically what you are doing!

Ian
Guest








PostPosted: Wed Jan 03, 2007 3:30 pm     Reply with quote

It works now. I didnt use the '&' sign for address, and it didnt know which address to start from for the 2 bytes under consideration.
Thank You though.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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