Created
May 27, 2014 03:18
-
-
Save jsfaint/158cc1a9f907f1e82d09 to your computer and use it in GitHub Desktop.
BCD code to decimal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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