Skip to content

Instantly share code, notes, and snippets.

@nyg
Last active March 2, 2024 21:28
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 nyg/4c29ba0da5655029754a4e3d3e6fb21c to your computer and use it in GitHub Desktop.
Save nyg/4c29ba0da5655029754a4e3d3e6fb21c to your computer and use it in GitHub Desktop.
Euclidean division in C.
#include <stdio.h>
int main(int argc, const char** argv) {
unsigned int a = 0xDEADBEEF;
unsigned int b = 0xBABE;
unsigned int q = a / b;
unsigned int r = a % b;
printf("%u = %u * %u + %u\n", a, q, b, r);
printf("%X = %X * %X + %X\n", a, q, b, r);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment