將字串型態表示的16位元數字轉為整數資料型態
傳入的參數可為 " ffbc","FFbC","0xFFFC", "12F4"
//字元 HEX 轉 OCT
int chex2oct(char ch[]){
unsigned int i, j[10], leng, leng_s=0, chex=0;
unsigned int hex16[] = {1, 16, 256, 4096, 65536, 1048576, 16777216,268435456};
leng = strlen(ch);
for(i=0; i<leng; i++) {
if(ch[i]>47 && ch[i]<58) j[leng_s++] = ch[i] - 48;
else {
switch (ch[i]){
case 'a': case 'A': j[leng_s++] = 10; break;
case 'b': case 'B': j[leng_s++] = 11; break;
case 'c': case 'C': j[leng_s++] = 12; break;
case 'd': case 'D': j[leng_s++] = 13; break;
case 'e': case 'E': j[leng_s++] = 14; break;
case 'f': case 'F': j[leng_s++] = 15; break;
}
}
}
for(i=0; i<leng_s; i++) chex += j[i] * hex16[leng_s - i - 1];
return chex;
}
沒有留言:
張貼留言