Skip to content

Instantly share code, notes, and snippets.

@jsfaint
Created May 27, 2014 03:18
Show Gist options
  • Save jsfaint/158cc1a9f907f1e82d09 to your computer and use it in GitHub Desktop.
Save jsfaint/158cc1a9f907f1e82d09 to your computer and use it in GitHub Desktop.
BCD code to decimal
#include <stdio.h>
unsigned char bcd2dec(unsigned char c);
unsigned char bcd2dec(unsigned char c)
{
unsigned char dec;
dec = (c>>4) & 0x07;
dec = (dec<<3) + (dec<<1) + (c & 0x0F);
return dec;
}
int main(int argc, const char *argv[])
{
printf("%u\n", bcd2dec((unsigned char)0x19));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment