Possible Duplicate:
Convert a long hex string in to int array with sscanf
我以前曾看到过这方面的一些议题,但大多数解决办法都是在沙尔(因为你很容易!) 。
在C这样做是否容易? 这是我的解决办法。 我知道这在概念上并不复杂,但我对C扼杀操纵和处理问题感到可怕。
在帮助下,gu!
页: 1
奥凯,因此我解决了这一问题,我还有另一个问题(我不想开新的路!) 。 以下是我对特定法典的修改,职能要求和产出。
void htoi(const char *ptr, char *binAddr) {
char value[32] = "";
char ch = *ptr;
int i;
const char* quads[] = {"0000", "0001", "0010", "0011", "0100", "0101",
"0110", "0111", "1000", "1001", "1010", "1011",
"1100", "1101", "1110", "1111"};
while (ch == || ch == )
ch = *(++ptr);
for (i = 0; i < 8; i++) {
if (ch >= 0 && ch <= 9 )
strncat(value, quads[ch - 0 ], 4);
if (ch >= A && ch <= F )
strncat(value, quads[10 + ch - A ], 4);
if (ch >= a && ch <= f )
strncat(value, quads[10 + ch - a ], 4);
ch = *(++ptr);
printf("%s
", value);
}
*binAddr = *value;
}
我的职责是:
char line[11], hexAddr[8], binAddr[32];
htoi(hexAddr, binAddr);
printf("%s
", binAddr);
这里是产出(当投入时为001133c0):
0000
单位:千美元
单位:千美元0001
单位:千美元00010001
单位:千美元000100010011
单位:千美元0001000100110011
单位:千美元00010001001100111100
单位:千美元000100010011001111000000
页: 1
The last line (with the special characters) is the printf(binAddr) in the main function above. It is clear from the printf statements inside the function that the binary code is being constructed correctly.
我再说一遍,这并不值得一提操纵。 我做了什么错误?