Skip to content

Instantly share code, notes, and snippets.

@clausecker
Last active December 2, 2015 19:35
Show Gist options
  • Select an option

  • Save clausecker/3d957c8c0b7a05960dda to your computer and use it in GitHub Desktop.

Select an option

Save clausecker/3d957c8c0b7a05960dda to your computer and use it in GitHub Desktop.
extern unsigned
decimal2dpd(unsigned a, unsigned b, unsigned c)
{
unsigned result = c & 1 | (a & 7) << 7;
if (a < 8) {
if (b < 8)
return result | b << 4 | c;
else
return result | (c > 7 ? 0104 : (c & 6) << 4) | (b & 1) << 4 | 0012;
} else {
result |= (b & 1) << 4;
if (c < 8)
return result | (c & 6) << 7 | (b > 7 ? 0002 : b << 4) | 0014;
else
return result | (b > 7 ? 0100 : (b & 6) << 7) | 0056;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment