Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- char toChar(int n){
- if(n < 10) return '0' + n;
- return 'a' + n - 10;
- }
- void printNumAs(unsigned int num, int bit){
- int tmp[256], i, n = pow(2, bit) - 1;
- for(i = 0; num > 0; i++){
- tmp[i] = num & n;
- num >>= bit;
- }
- while(i-- > 0){
- printf("%c", toChar(tmp[i]));
- }
- }
- int main() {
- int n;
- printf("10進数 : ");
- scanf("%d", &n);
- printf("\n16進数 : ");
- printNumAs(n, 4);
- printf("\n 8進数 : ");
- printNumAs(n, 3);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement