Advertisement
Guest User

Untitled

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