import bcd2char() and char2bcd() from OpenBSC

This commit is contained in:
Harald Welte 2010-03-04 10:50:32 +01:00
parent aebe08c71f
commit a73e2f9acb
2 changed files with 17 additions and 0 deletions

View File

@ -13,5 +13,8 @@ struct value_string {
const char *get_value_string(const struct value_string *vs, uint32_t val);
int get_string_value(const struct value_string *vs, const char *str);
char bcd2char(uint8_t bcd);
/* only works for numbers in ascci */
uint8_t char2bcd(char c);
#endif

View File

@ -30,3 +30,17 @@ int get_string_value(const struct value_string *vs, const char *str)
}
return -EINVAL;
}
char bcd2char(uint8_t bcd)
{
if (bcd < 0xa)
return '0' + bcd;
else
return 'A' + (bcd - 0xa);
}
/* only works for numbers in ascci */
uint8_t char2bcd(char c)
{
return c - 0x30;
}