Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.61 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("%d\n", x);
  60.     }
  61. }
  62.  
  63. void SETBITS(int x)
  64. {
  65.     int count = 0;
  66.     int move = 0;
  67.     int byte = 0;
  68.     int i, b;
  69.    
  70.     for (i = 31; i >= 0; i--)
  71.     {
  72.         move = i % 8;
  73.  
  74.         if ((move == 6 && i != 30) || i == 0)
  75.         {
  76.             printf("Byte %d", byte);
  77.             printf(" Count: %d\n", count);
  78.            
  79.             count = 0;
  80.             byte = byte + 1;
  81.         }
  82.             b = x >> i;
  83.  
  84.             if(b & 1)
  85.             {
  86.                 count = count + 1;
  87.             }
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement