[英]Convert base 32 bit decoded string to decimal
我有一个基于32位解码的字符串,现在我想对该字符串进行解码,我也想将任何字符串编码为基于32位解码的字符串。 有没有办法,任何算法(甚至在C中)或任何API都可以解决这个问题。 提前感谢。
我不确定是否理解您的问题,但是如果要将基数32转换为基数10(十进制),请执行以下操作:
#include <stdio.h>
#include <string.h>
#include <math.h>
#define BASE 32
unsigned int convert_number (const char *s) {
unsigned int len = strlen(s) - 1;
unsigned int result = 0;
char start_ch = 0, ch;
while(*s != '\0') {
ch = *s;
if (ch >= 'a') {
start_ch = 'a' - 10;
} else if (ch >= 'A') {
start_ch = 'A' - 10;
} else {
start_ch = '0';
}
if(len >= 0)
result += (ch - start_ch) * pow(BASE, len);
else
result += (ch - start_ch);
++s;
--len;
}
return result;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.