Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream.h>
- #include <cstring>
- #define DIG "0123456789ABCDEFGHIGKLMNOPQRSTUVWXYZ"
- using namespace std;
- int Atoi(char *s, int p){
- int i, a, digit[256] = {0};
- for(i = 0; DIG[i]; i++)
- digit[DIG[i]] = i;
- for(i = a = 0; s[i]; i++)
- a = a * p + digit[s[i]];
- return a;
- }
- void Itoa(int a, int p, char *s) {
- static int i = 0, n;
- if (a) {
- ++i;
- Itoa(a / p, p, s);
- s[n - i--] = DIG[a % p];
- }
- else
- s[n = i] = '\0';
- }
- int main(){
- char s[1024] = "29234652";
- Itoa(Atoi(s, 10), 36, s);
- cout << s << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment