#include <stdio.h>
#include <string.h>
// 将一个不定长的字符串转换为一个定长的数字
// 输入:字符串
// 输出:16位数字
/* 转换格式:将字符串分成n组,每组16个字符,
将n组字符串相应位置的字符相加,如果值不是个位数,
则各个位再进行相加,直到为个位数为止,
最终得出的16个数字即要求输出的数字 */
#define N 1000
int main()
{
char str[N];
int res[16] = {0};
scanf ("%s", str);
int len = strlen(str);
int i;
for (i = 0; i < 16; i++){
int temp = 0;
while (temp+i<len){
res[i] += str[temp+i];
temp += 16;
}
while (res[i] > 15){
res[i] = res[i]%16 + res[i]/16;
}
}
for (i = 0; i < 16; i++){
printf("%X", res[i]);
}
printf ("\n");
return 0;
}
;
字符串转定常数.c
最新推荐文章于 2022-07-27 19:39:45 发布