|
|
View previous topic :: View next topic |
Author |
Message |
Tagge
Joined: 23 Aug 2005 Posts: 93
|
Calculating BCC? |
Posted: Thu Jan 19, 2006 8:24 am |
|
|
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
|
|
Posted: Thu Jan 19, 2006 9:31 am |
|
|
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 |
|
|
|
|
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
|