Blame view
include/bcd.h
548 Bytes
758c037ae
|
1 2 3 4 |
/* Permission is hereby granted to copy, modify and redistribute this code * in terms of the GNU Library General Public License, Version 2 or later, * at your option. */ |
e84aba135
|
5 6 |
/* inline functions to translate to/from binary and binary-coded decimal * (frequently found in RTC chips). |
758c037ae
|
7 8 9 10 |
*/ #ifndef _BCD_H #define _BCD_H |
be47aa652
|
11 |
static inline unsigned int bcd2bin(unsigned int val) |
e84aba135
|
12 |
{ |
be47aa652
|
13 |
return ((val) & 0x0f) + ((val & 0xff) >> 4) * 10; |
e84aba135
|
14 |
} |
be47aa652
|
15 |
static inline unsigned int bin2bcd(unsigned int val) |
e84aba135
|
16 17 18 |
{ return (((val / 10) << 4) | (val % 10)); } |
758c037ae
|
19 20 |
#endif /* _BCD_H */ |