blob: 9ecd328284e9de20a293a96dff9bc655c6d529ea [file] [log] [blame]
Stefan Roese758c0372007-10-21 08:16:12 +02001/* Permission is hereby granted to copy, modify and redistribute this code
2 * in terms of the GNU Library General Public License, Version 2 or later,
3 * at your option.
4 */
5
Albin Tonnerree84aba12009-08-13 15:31:11 +02006/* inline functions to translate to/from binary and binary-coded decimal
7 * (frequently found in RTC chips).
Stefan Roese758c0372007-10-21 08:16:12 +02008 */
9
10#ifndef _BCD_H
11#define _BCD_H
12
Simon Glassbe47aa62015-04-20 12:37:20 -060013static inline unsigned int bcd2bin(unsigned int val)
Albin Tonnerree84aba12009-08-13 15:31:11 +020014{
Simon Glassbe47aa62015-04-20 12:37:20 -060015 return ((val) & 0x0f) + ((val & 0xff) >> 4) * 10;
Albin Tonnerree84aba12009-08-13 15:31:11 +020016}
17
Simon Glassbe47aa62015-04-20 12:37:20 -060018static inline unsigned int bin2bcd(unsigned int val)
Albin Tonnerree84aba12009-08-13 15:31:11 +020019{
20 return (((val / 10) << 4) | (val % 10));
21}
Stefan Roese758c0372007-10-21 08:16:12 +020022
23#endif /* _BCD_H */