+/*
+ ref http://www.csm.ornl.gov/~dunigan/crc.html
+ Returns the value v with the bottom b [0,32] bits reflected.
+ Example: reflect(0x3e23L,3) == 0x3e26
+*/
+uint32_t reflect(uint32_t v, int b) {
+ uint32_t t = v;
+ for ( int i = 0; i < b; ++i) {
+ if (t & 1)
+ v |= BITMASK((b-1)-i);
+ else
+ v &= ~BITMASK((b-1)-i);
+ t >>= 1;
+ }
+ return v;
+}
+
+void num_to_bytes(uint64_t n, size_t len, uint8_t* dest) {