Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define LOW(exp) ((exp) & 0xFF)
- #define HIGH(exp) (((exp) & 0xFF00) >> 8)
- uint16_t prng(uint16_t v) {
- uint16_t low = LOW(v);
- uint16_t high = HIGH(v);
- uint16_t mul_low = low * 5;
- //high byte is ignored
- uint8_t mul_high = LOW(high * 5);
- //need to check for overflow, since the final addition is adc as well
- uint16_t v1 = mul_high + HIGH(mul_low) + 1;
- uint8_t carry = HIGH(v1) ? 1 : 0;
- uint16_t v2 = (LOW(v1) << 8) + LOW(mul_low);
- return v2 + 0x11 + carry;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement