我有一个小程序,可以将以10为底的数字转换为以36为底的数字。这是Python代码,它可以按预期工作。
def numToKey(num):
start = 0x04;
i = 0;
for i in range(0,num):
start+=1
return start;
def largeNumToKeyboard(num):
a = num / 1296;
ar = num % 1296;
b = ar / 36;
c = ar % 36;
a = numToKey(a);
b = numToKey(b);
c = numToKey(c);
newb = b;
if(a == b):
newb = 0x2D;
if(c == b):
c = 0x2E;
print a,newb,c
largeNumToKeyboard(0)
largeNumToKeyboard(200)
输出是
4 45 46
4 9 24
“ 4 45 46”正确表示0,而“ 4 9 24”正确表示200。
但是问题是,在将其转换为C代码后,它停止工作。
#include <stdio.h>
int main(int argc, char **argv)
{
printf("hello world\n");
largeNumToKeyboard(0);
largeNumToKeyboard(200);
return 0;
}
char numToKey(char num) {
char start = 0x04;
char i = 0;
for (i = 0; i < num; i++) {
start++;
}
return start;
}
void largeNumToKeyboard(int num) {
char a = num / 1296;
char ar = num % 1296;
char b = ar / 36;
char c = ar % 36;
a = numToKey(a);
b = numToKey(b);
c = numToKey(c);
char newb = b;
if(a == b){
newb = 0x2D;
}
if(c == b){
c = 0x2E;
}
printf("%d ",a);
printf("%d ",newb);
printf("%d\r\n",c);
}
现在的输出是
4 45 46
4 45 46
我不明白为什么对于200的输入,C代码给我错误的输出,但是python代码给我正确的输出。我感觉它与模数有关,但我无法弄清楚。请帮忙!谢谢!
慕尼黑8549860
相关分类