编写一个函数,转换整型数为BCD编码二进制数。比如1234转换为0x00001234。
源代码:1不能处理大于5的数字不知道哪里的问题。
#include <math.h> #include <stdio.h> int main() { int a = 6249; int b = 0; int c = 0; int i = 0, j = 0; while ( a > 10) { b = a % 10; c |= (b << 4*7); printf("%x\n", c); c = c >> 4; printf("%x\n", c); a = a / 10; i++; } printf("%d\n",i); c |= (a << 4*7); printf("%x\n", c); c = c >> (4*(8-i-1)); printf("%8x\n", c); }
时间: 2024-10-06 09:46:07