main.c (853B)
1 #include <stdio.h> 2 #include <string.h> 3 int main() { 4 char s[1000]; 5 void itob(), itoh(), reverse(); 6 7 itob(42,s); 8 printf("42 in base-2 is %s\n", s); 9 itoh(42,s); 10 printf("42 in base-16 is %s\n", s); 11 12 itob(16,s); 13 printf("16 in base-2 is %s\n", s); 14 itoh(16,s); 15 printf("16 in base-16 is %s\n", s); 16 17 itob(59,s); 18 printf("59 in base-2 is %s\n", s); 19 itoh(59,s); 20 printf("59 in base-16 is %s\n", s); 21 22 itob(100,s); 23 printf("100 in base-2 is %s\n", s); 24 itoh(100,s); 25 printf("100 in base-16 is %s\n", s); 26 27 itob(254,s); 28 printf("254 in base-2 is %s\n", s); 29 itoh(254,s); 30 printf("254 in base-16 is %s\n", s); 31 } 32 33 void reverse(t) 34 char t[]; 35 { 36 int i, j, len; 37 char tmp; 38 len = strlen(t); 39 for(i=0, j=len-1;;i++,j--) { 40 if (j<i) break; 41 tmp = t[i]; 42 t[i] = t[j]; 43 t[j] = tmp; 44 } 45 return; 46 }