1
是否有算法或公式可以將任何基地n,例如2到36轉換爲二進制?我瀏覽過網頁,無法找到我要找的內容。轉換任何基地到二進制
是否有算法或公式可以將任何基地n,例如2到36轉換爲二進制?我瀏覽過網頁,無法找到我要找的內容。轉換任何基地到二進制
讓你開始的東西。
unsigned strtou(const char *s, unsigned base) {
unsigned y = 0;
while (*s) {
unsigned digit;
if (isdigit(*s)) digit = ch - '0';
else if (isupper(*s)) digit = ch - 'A' + 10;
else if (islower(*s)) digit = ch - 'a' + 10;
else Handle_IllegalDigit();
if (digit >= base) Handle_IllegalDigit();
y = y*base + digit;
s++;
}
return y;
}
感謝那正是我需要的 – Alfred 2014-10-01 01:29:17