Early in the course the ALU has no bitwise operators you can count on, yet programs such as hash functions and random number generators are built from XOR and bit rotations. Rebuild them from arithmetic.
Words are signed 32-bit integers: a 32-bit pattern is represented by its two's-complement value in . Use only +, -, *, floor division //, floor modulo %, comparisons and plain integer constants such as powers of two. The bitwise operators ^, &, |, ~, << and >> are not allowed. Tests run your functions on an integer type that raises an error if any of them is used.
Implement:
wrap32(x): reduce any integer to the signed 32-bit value with the same low 32 bits.xor32(a, b): the signed 32-bit word whose bit pattern is the XOR of the patterns of a and b.rotl32(a, r): rotate the 32-bit pattern of a left by r positions, for 1 <= r <= 31, and return it as a signed word.Each function must return the same type it was given (do not convert to plain int).