Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- char *itoa(unsigned int val, int base)
- {
- static char buf[32] = {0};
- int i = 32;
- for(; val && i; --i, val /= base)
- buf[i] = "0123456789abcdef"[val % base];
- return &buf[i+1];
- }
- int main (void)
- {
- int n;
- printf("Enter a value: ");
- scanf("%d", &n);
- printf("%d -> hex %s\n", n, itoa(n, 16));
- printf("%d -> oct %s\n", n, itoa(n, 8));
- printf("%d -> bin %s\n", n, itoa(n, 2));
- system("pause > nul");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment