1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| #include <stdlib.h>
#include <stdio.h>
#define INPUT_STRING "Hello"
unsigned char getFootPrint1(char* text)
{
unsigned char footprint = 0;
while(*text != '\0')
footprint += (*text++);
return footprint ^0xff;
}
unsigned char getFootPrint2(char* text)
{
unsigned char footprint = 0;
unsigned char divisor = 1;
while(*text != '\0')
footprint += (*text++) * divisor++;
return footprint;
}
int main (void)
{
printf("%02X %02X\n", getFootPrint1(INPUT_STRING), getFootPrint2(INPUT_STRING));
return 0;
} |
Partager