1.整形转成字符串数组
void Int2Str(unsigned char* str, unsigned long int intnum) { unsigned long int i, Div = 1000000000, j = 0, Status = 0; //32位无符号数最大是10位整数,所以Div=10 0000 0000 for (i = 0; i < 10; i++) { str[j++] = (intnum / Div) + '0';//取最高位 转化成字符 intnum = intnum % Div;//去掉最高位 Div /= 10;//还剩下10-i位要转换 if ((str[j-1] == '0') && (Status == 0))//忽略最高位的'0' { j = 0; } else { Status++; } } }
2.两位整形数转为BCD码(将引号删去即得整形的0 1)
void getBCD(uint NUM) { shi=NUM/10; ge=NUM%10; if(ge>0&&(ge!=2&&ge!=4&&ge!=6&&ge!=8)) ASTR[7]='1'; else ASTR[7]='0'; if(ge/2>0&&(ge!=4&&ge!=5&&ge!=8&&ge!=9)) ASTR[6]='1'; else ASTR[6]='0'; if(ge/4>0&&(ge!=8&&ge!=9)) ASTR[5]='1'; else ASTR[5]='0'; if(ge>=8) ASTR[4]='1'; else ASTR[4]='0'; if(shi>0&&(shi!=2&&shi!=4&&shi!=6&&shi!=8)) ASTR[3]='1'; else ASTR[3]='0'; if(shi/2>0&&(shi!=4&&shi!=5&&shi!=8&&shi!=9)) ASTR[2]='1'; else ASTR[2]='0'; if(shi/4>0&&(shi!=8&&shi!=9)) ASTR[1]='1'; else ASTR[1]='0'; if(shi>=8) ASTR[0]='1'; else ASTR[0]='0'; }