SHARE
TWEET

Romb - KZ 2018

a guest Dec 3rd, 2019 98 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdint.h>
  3.  
  4. #define ITER 8
  5.  
  6. void pbyte(uint8_t x)
  7. {
  8.     for (uint8_t i = 0; i < 8; i++)
  9.         printf("%d", ((x << i) & 0x80) ? 1 : 0);
  10. }
  11.  
  12. uint8_t reverse(uint8_t x)
  13. {
  14.     uint8_t out = 0;
  15.     for (uint8_t i = 0; i < 8; i++) {
  16.         out = (out << 1) | (x & 0b1);
  17.         x >>= 1;
  18.     }
  19.     return out;
  20. }
  21.  
  22. static uint8_t t = 0;
  23.  
  24. void mod(void)
  25. {
  26.    static uint8_t flag = 0;
  27.  
  28.    if (!t) {
  29.        t = 0x18;
  30.        flag = flag ? 0 : 1;
  31.        return;
  32.    }
  33.    else if (t == 0x18 && !flag) {
  34.        t = 0x00;
  35.        return;
  36.    }
  37.    else if (t == 0x81)
  38.         flag = flag ? 0 : 1;
  39.  
  40.    t &= 0x0F;
  41.    if (flag)
  42.        t >>= 1;
  43.    else
  44.        t <<= 1;
  45.    
  46.    t |=  reverse(t);
  47. }
  48.  
  49. int main(void)
  50. {
  51.    
  52.     uint8_t n = 2;
  53.     for (uint8_t i = 0; i < n * ITER; i++) {
  54.         pbyte(t);
  55.         printf("\n");
  56.         mod();
  57.     }
  58.  
  59.     return 0;  
  60. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top