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 support@ccsinfo.com

Bit shifting

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



Joined: 21 Oct 2010
Posts: 85

View user's profile Send private message

Bit shifting
PostPosted: Fri Oct 05, 2012 2:41 pm     Reply with quote

Hello,

I'm confused...

I have a char array
Code:

a[0] = '0';
a[1] = '1';

now I would like to set the output with the a[1] value...

for example:
Code:

a[1] = 3;
out = 00000100;

or
Code:

a[1]  = 7;
out = 01000000;

I try:
Code:

out =1;
out = out << a[1];
output_d(out);


not working..

anybody an idea?

thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Oct 05, 2012 4:54 pm     Reply with quote

You want to convert a bit number to a bitmask. Use a lookup table.
With the following table placed above main(), you can now put in code
in main() to get the bitmask. Use a number from 0 to 7 as the index
to get the bitmask for bit number 0 to 7. For bit 0, you will get 0x01,
and for bit 7 you will get 0x80, etc.
Code:

int8 const bitmask_table[] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
 

To use your incoming numbers as index values for this table, you will
need to convert them from ASCII characters to binary digits in the range
from 0 to 7.

This post may have some hints.
http://www.ccsinfo.com/forum/viewtopic.php?t=48590&start=3
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