The_Law

Untitled

Oct 15th, 2018
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.73 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <fcntl.h>
  3. #include <unistd.h>
  4. #include <string.h>
  5. #include <limits.h>
  6.  
  7. int
  8. main(int argc, char* argv[])
  9. {
  10.     while (1)
  11.     {
  12.         unsigned char s[CHAR_BIT];
  13.         memset(s, 0, sizeof(s));
  14.  
  15.         int it = 0;
  16.         while (it < CHAR_BIT) {
  17.             unsigned char curr;
  18.             if (scanf("%hhx", &curr) == 1) {
  19.                 for (int i = 0; i < CHAR_BIT; ++i) {
  20.                     s[i] = curr & (1 << i) ? s[i] | (1 << it) : s[i];
  21.                 }
  22.             } else {
  23.                 return 0;
  24.             }
  25.             ++it;
  26.         }
  27.  
  28.         for (int i = 0; i < CHAR_BIT; ++i) {
  29.             printf("%hhx ", s[i]);
  30.         }
  31.         printf("\n");
  32.     }
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment