Programming challenge:
Write me a function with this signature in C#:
public (unsafe?) long Reverse(long i, int bits)
...to flip the endian-ness (LSB/MSB) of a long, but just the # of significant bits specified.
Example, if the input is 376, with bits=11, the output is 244 (decimal, base 10).
376 = 00000101111000244 = 00000011110100
Example, if the input is 900, with bits=11, the output is 270.
900 = 00001110000100270 = 00000100001110
Example, if the input is 900, with bits=12, the output is 540.
900 = 00001110000100540 = 00001000011100
Example, if the input is 154, with bits=4, the output is 5.
154 = 000000100110105 = 00000000000101
And make it FAST...;)
Ads by The Lounge