Created
February 17, 2017 12:28
-
-
Save tkouba/738fcc6b631d955b9db3181067793ca2 to your computer and use it in GitHub Desktop.
Reverse UInt64 with bits width of groups. Reverse bits (bits = 1), reverse half-bytes (bits = 4, same as reverse hexadecimal string value).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static UInt64 ReverseUInt64(UInt64 x, int bits = 1) | |
{ | |
UInt64 b = 0; | |
UInt64 mask = 0; | |
for (int i = 0; i < bits; i++) | |
{ | |
mask = (mask << 1) | 0x1; | |
} | |
for (int i = 0; i < 64 / bits; i++) | |
{ | |
b = ((b << bits) | (x & mask)); | |
x = (x >> bits); | |
} | |
return b; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment