Skip to content

Instantly share code, notes, and snippets.

@BrynM
Created October 7, 2025 04:49
Show Gist options
  • Select an option

  • Save BrynM/0253d220c5176c2de3ce725366df121e to your computer and use it in GitHub Desktop.

Select an option

Save BrynM/0253d220c5176c2de3ce725366df121e to your computer and use it in GitHub Desktop.
Swap Byte Macro
/*
* This should work for ints too, but we only need bytes. Either way, both args
* must be the same type for XOR to work properly.
* https://dev.to/pauljlucas/a-generic-swap-macro-in-c-22me
* https://www.hackerearth.com/practice/notes/swapping-without-a-temporary-variable-take-care/
* https://dev.to/pauljlucas/cc-preprocessor-macros-fh5
*/
#define SWAP_BYTE(A, B) do { ( (A) ^= (B) ^= (A) ^= (B) ); } while (0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment