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

Calculating BCC?

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



Joined: 23 Aug 2005
Posts: 93

View user's profile Send private message Visit poster's website

Calculating BCC?
PostPosted: Thu Jan 19, 2006 8:24 am     Reply with quote

Hi, can someone help me to do a "driver" to calculate the BCC of a string of chars, bytes? from a printf function.
I know BCC is the xor of all the chars in a string,but...
Is there any ready function for this in CCS?
Something like this?
Code:

char bcc_calc(void){
char bcc=0;
char const* p=string1;
  while(*p)
     bcc^=*p++;
return bcc;
}
void func(char bcc){
printf("%s",string1)
putc(bcc_calc());
}
Ttelmah
Guest







PostPosted: Thu Jan 19, 2006 9:31 am     Reply with quote

There is not an inbuilt function, but you can take advantage of the ability of printf, to 'print' to another function.
So:
Code:

int8 bcc;
#define RESET_BCC bcc=0
void putcsum(int8 val) {
   bcc^=val;
   putc(val);
}


//Then in your main code:

RESET_BCC;
printf(putcsum,string);
putc(bcc);


What happens here, is that you set the 'bcc' value to zero (RESET_BCC), then printf the characters, to the routine 'putcsum', which actually outputs them, and xors them into bcc.
You then just send the checksum.

The big advantage, is that the code only has to access the array once for each character. Array accesses are slow.

Best Wishes
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