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

Bits and Bytes

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



Joined: 08 Dec 2009
Posts: 2

View user's profile Send private message

Bits and Bytes
PostPosted: Tue Dec 08, 2009 4:28 am     Reply with quote

Hello all,

I wonder if you can help me - I am trying to insert an extra bit into a printf RS232 output shown below:

Code:

int number=10;
printf(%c",number);


Output bit stream looks like 01010000.

What I want to do is be able to add a bit so that the output looks like this: 01011000. I am not sure how to go about it.


Adding a 1 with putc(1); creates a new byte so the output is
0101000010000000 which is not the output I am looking for.

I can't change "number" to include this 1 as it will be a variable.

I could well be doing this the wrong way - I am learning about RS232 and am only beginning to understand. Hopefully someone can help. Razz
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Tue Dec 08, 2009 4:56 am     Reply with quote

OK, the bit stream is actually inverted so the value of 10 is actually
00001010 and you want to add the extra bit 00010000

You can do this by oring the 2 values

Code:

int number = 10; // in hex 0x0A

printf("%c", number | 0x10);  // 0x10 is hex for 00010000
// Will out put 0x1A or 00011010 bit stream = 01011000
richste



Joined: 08 Dec 2009
Posts: 2

View user's profile Send private message

PostPosted: Tue Dec 08, 2009 5:20 am     Reply with quote

Thanks this works perfectly, it was a big help
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