Advertisement
Guest User

Untitled

a guest
Jun 10th, 2015
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #define LOW(exp) ((exp) & 0xFF)
  2. #define HIGH(exp) (((exp) & 0xFF00) >> 8)
  3.  
  4. uint16_t prng(uint16_t v) {
  5.     uint16_t low = LOW(v);
  6.     uint16_t high = HIGH(v);
  7.  
  8.     uint16_t mul_low = low * 5;
  9.     //high byte is ignored
  10.     uint8_t mul_high = LOW(high * 5);
  11.  
  12.     //need to check for overflow, since the final addition is adc as well
  13.     uint16_t v1 = mul_high + HIGH(mul_low) + 1;
  14.     uint8_t carry = HIGH(v1) ? 1 : 0;
  15.  
  16.     uint16_t v2 = (LOW(v1) << 8) + LOW(mul_low);
  17.  
  18.     return v2 + 0x11 + carry;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement