36 lines
618 B
C
36 lines
618 B
C
#include "conv.h"
|
|
|
|
#include <gint/std/string.h>
|
|
|
|
uint64_t pow(const int n, unsigned int p);
|
|
|
|
uint64_t atoi(char *s) {
|
|
int taille = strlen(s);
|
|
uint64_t retour = 0;
|
|
for(int puissance = 0; puissance < taille; ++puissance) {
|
|
retour += (s[taille-1-puissance] - '0') * pow(10, puissance);
|
|
}
|
|
return retour;
|
|
}
|
|
|
|
void itoa(char *s, uint64_t a) {
|
|
int i = 0, j;
|
|
char c;
|
|
while(a) {
|
|
s[i++] = '0' + a%10;
|
|
a/=10;
|
|
}
|
|
s[i] = 0;
|
|
for(j = 0; j < i/2; ++j) {
|
|
c = s[j];
|
|
s[j] = s[i-j-1];
|
|
s[i-j-1] = c;
|
|
}
|
|
}
|
|
|
|
uint64_t pow(const int n, unsigned int p) {
|
|
uint64_t retour = 1;
|
|
for(; p; --p) retour *= n;
|
|
return retour;
|
|
}
|