Skip to content

Instantly share code, notes, and snippets.

@lion328
Last active June 1, 2018 12:54
Show Gist options
  • Save lion328/5b298539e930dba927df414658cb8cc6 to your computer and use it in GitHub Desktop.
Save lion328/5b298539e930dba927df414658cb8cc6 to your computer and use it in GitHub Desktop.
Branchless Grading
#include <stdio.h>
#include <stdint.h>
int main()
{
uint8_t buf[4] = {0};
fgets(buf, sizeof(buf), stdin);
int32_t i = (buf[2] << 8) | (buf[0]);
int32_t g = (i - 0xA35) >> 31 & 0x33;
g |= (~-g & (i - 0xA38)) >> 31 & buf[0];
g |= ~-g >> 31 & 0x38;
g = 0x79 - g;
putchar(g);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment