- #include <math.h> //pour pow
-
- #define ASCIInumber 48
-
- char str[31];
-
- unsigned long BaseToDecimal(char string[])
- {
- unsigned long value = 0;
-
- long i;
-
- for (i=0;i<=strlen(string)-1;i++)
- value = (value + string[i] - ASCIInumber) * 2;
- return value / 2;
- }
-
- int DecimalToBase(long n)
- {
- int i = 0, j;
-
- for (j=0;j<=30;j++) str[j] = 0;
-
- while(pow(2,i) <= n) i++;
-
- if (!i) str[0] = ASCIInumber;
-
- while (n)
- {
- i--;
- str[i] = (n%2)+ASCIInumber;
- n = n / 2;
- }
- }
-
#include <math.h> //pour pow
#define ASCIInumber 48
char str[31];
unsigned long BaseToDecimal(char string[])
{
unsigned long value = 0;
long i;
for (i=0;i<=strlen(string)-1;i++)
value = (value + string[i] - ASCIInumber) * 2;
return value / 2;
}
int DecimalToBase(long n)
{
int i = 0, j;
for (j=0;j<=30;j++) str[j] = 0;
while(pow(2,i) <= n) i++;
if (!i) str[0] = ASCIInumber;
while (n)
{
i--;
str[i] = (n%2)+ASCIInumber;
n = n / 2;
}
}