Skip to content

Instantly share code, notes, and snippets.

@azat
Created March 26, 2014 22:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azat/9794985 to your computer and use it in GitHub Desktop.
Save azat/9794985 to your computer and use it in GitHub Desktop.
/**
* @example 0x1122334455667788 => 0x4477225588336611
*
* NB: Do not use this functin like a {cryptographic,} hash function
*/
static inline uint64_t memfryu64(uint64_t a, u8 off)
{
uint64_t b = 0;
for (u8 i = 0; i < sizeof(uint64_t); ++i) {
u8 aOff = (i + ((i % 2) ? 0 : off)) % sizeof(uint64_t);
b = (b << __CHAR_BIT__) | (u8)(a >> (__CHAR_BIT__ * aOff));
}
return b;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment