Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.49 KB | None | 0 0
  1. #ifdef HEXADECIMAL
  2. #define NUM 0
  3. #define VAR "hexadecimal"
  4. #endif
  5.  
  6. #ifdef BIN
  7. #define NUM 1
  8. #define VAR "binary"
  9. #endif
  10.  
  11. #ifdef DECIMAL
  12. #define NUM 2
  13. #define VAR "decimal"
  14. #endif
  15.  
  16. #ifndef XOUTER
  17. #define XOUTER(x)  ((x & 0x000000FF) << 24) | ((x & 0xFF000000) >> 24) | (x & 0x00FFFF00)
  18. #endif
  19.  
  20. #ifndef XINNER
  21. #define XINNER(x)  ((x & 0x00FF0000) >> 8) | ((x & 0x0000FF00) << 8) | (x & 0xFF0000FF)
  22. #endif
  23.  
  24. void DISPLAY(int x, int y)
  25. {  
  26.     int i, j;
  27.  
  28.     if (y == 0)
  29.     {
  30.         printf("0x%x\n", x);
  31.     }
  32.  
  33.     else if (y == 1)
  34.     {
  35.         for (i = 31; i >= 0; i--)
  36.         {
  37.             j = x >> i;
  38.                                                
  39.             if (j & 1)
  40.             {
  41.                 printf("1");
  42.             }  
  43.                                                
  44.             else
  45.             {
  46.                 printf("0");
  47.             }
  48.         }
  49.                                        
  50.         printf("\n");
  51.     }
  52.  
  53.     else if (y == 2)
  54.     {
  55.         printf(x + "\n");
  56.     }
  57. }
  58.  
  59. void SETBITS(int x)
  60. {
  61.     int count = 0;
  62.     int move = 0;
  63.     int byte = 0;
  64.     int i;
  65.    
  66.     for (i = 32; i >= 0; i--)
  67.     {
  68.         if ((x & 1) == 1)
  69.             count++;
  70.        
  71.         x = x >> 1;
  72.         move++;
  73.        
  74.         if(move == 8)
  75.         {
  76.             printf("Byte %d", byte);
  77.             printf(" Count: %d\n", count);
  78.            
  79.             count = 0;
  80.             move = 0;
  81.  
  82.             byte++;
  83.         }
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement