Skip to content

Instantly share code, notes, and snippets.

@MarcoCiaramella
Created May 28, 2022 10:56
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 MarcoCiaramella/cda522a8b6cbd5b0182a084bfa2eab42 to your computer and use it in GitHub Desktop.
Save MarcoCiaramella/cda522a8b6cbd5b0182a084bfa2eab42 to your computer and use it in GitHub Desktop.
swap endianess of unsigned int (32bit) and unsigned long long (64bit)
#define swap_endianess32(val) (((val>>24) & 0xffu) | ((val>>8) & 0xff00u) | ((val<<8) & 0xff0000u) | ((val<<24) & 0xff000000u))
#define swap_endianess64(val) (((val>>56) & 0xffull) | ((val>>40) & 0xff00ull) | ((val>>24) & 0xff0000ull) | ((val>>8) & 0xff000000ull) | ((val<<8) & 0xff00000000ull) | ((val<<24) & 0xff0000000000ull) | ((val<<40) & 0xff000000000000ull) | ((val<<56) & 0xff00000000000000ull))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment