sprintf(ascii,"%X",number) // number = 63 is a decimal integer`
char ascii[] = {51, 70, 0, 0, 0, .... }
其顯示爲 「3F」
當我有
value = atoi(ascii);
它返回value = 3
不63.
我想要的東西是用sprintf進行十六進制轉換,但是顯示它將表格中的值保存爲另一個變量的小數點。
如何可以做到?
sprintf(ascii,"%X",number) // number = 63 is a decimal integer`
char ascii[] = {51, 70, 0, 0, 0, .... }
其顯示爲 「3F」
當我有
value = atoi(ascii);
它返回value = 3
不63.
我想要的東西是用sprintf進行十六進制轉換,但是顯示它將表格中的值保存爲另一個變量的小數點。
如何可以做到?
的問題的atoi不解析十六進制。你需要一個解析十六進制數字的函數。 sscanf(ascii, "%x", &i)
想到......
正如指出別人atoi
犯規解析十六進制。你可以試試這個:
#include <stdio.h>
int main()
{
char s[] = "3F";
int x;
sscanf(s, "%x", &x);
printf("%u\n", x);
}
,或者您可以使用strol這樣的:
printf("%u\n", strtol("3F", NULL, 16));
'atoi'只知道十進制數 - 使用'strtol'具有基數16或'sscanf'具有'%x'。 –
剛剛做'價值=數字'呢?'? – alk
因爲,我改變ASCII陣列的通過遞增或遞減的值的內容,轉換後成十進制然後保存。 –