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

question about binary code and variables

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







question about binary code and variables
PostPosted: Wed Mar 01, 2006 2:06 pm     Reply with quote

I need to read one bit from 3 pins A1 A2 A3. For example A1=1 A2=2 A3=3 then I need to see them as one binary number that is to say I need to put them side by side to create the number 101 and I it becomes a number to convert in decimal or to use.

how can I do?

Thanks from Italy
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Mar 01, 2006 2:35 pm     Reply with quote

Do you mean something like this?
Code:
int8 InputValue;
InputValue = input_a() & 0b00001110;  // Only get state of pins A1, A2, A3
InputValue = InputValue >> 1;         // A0 is not used, so shift value 1 bit to the right
printf("InputValue = %d\n", InputValue);
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Wed Mar 01, 2006 4:24 pm     Reply with quote

If what you want it is a binary representación of the type '101':

Code:

int n = 3;

 InputValue = input_a() & 0b00001110; 
 
 printf("Binary =  ");
 
 do
   {
    if(bit_test(InputValue,3))
      {putc('1'); }
    else
      {putc('0'); }

    rotate_left(&InputValue,1);
   }while(--n);
 



Humberto
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