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

What does this code mean?

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



Joined: 14 Jun 2005
Posts: 64

View user's profile Send private message

What does this code mean?
PostPosted: Fri Jun 24, 2005 9:17 am     Reply with quote

I'm looking at CCS's LT1298 code, specifically the line:

if((data_byte & 1)==0)

What does this mean and how does it work? I've copied the entire segment below.
Thanks!
Sophi

void write_adc_byte(byte data_byte, byte number_of_bits) {
byte i ;
delay_cycles(1); // was 2 us
for(i=0; i<number_of_bits; ++i) {
if((data_byte & 1)==0)
output_low(ADC_DIN);
else
output_high(ADC_DIN);
data_byte=data_byte>>1;
output_high(ADC_CLK);
delay_cycles(1); // was 50 uS
output_low(ADC_CLK);
delay_cycles(1); // was 50 uS
}
valemike
Guest







PostPosted: Fri Jun 24, 2005 9:29 am     Reply with quote

if((data_byte & 1)==0)

data_byte is an 8-bit value.
You 'and' it with 1, which is the same as and'ing it with '0000 0001'

Thus if the LSB (bit 0) is a 0, then your if-statement is TRUE.

Another way to write it would be:

if (!(data_byte & 0x01))

in assembly, it would be:
btfsc databyte, 0
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