blob: af4aa9c7baf8ace2f80e0a0ecb043d40d8b3f144 [file] [log] [blame]
Stefan Roese5a44c602007-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 Tonnerre8aca7202009-08-13 15:31:11 +02006/* inline functions to translate to/from binary and binary-coded decimal
7 * (frequently found in RTC chips).
Stefan Roese5a44c602007-10-21 08:16:12 +02008 */
9
10#ifndef _BCD_H
11#define _BCD_H
12
Albin Tonnerre8aca7202009-08-13 15:31:11 +020013#include <linux/types.h>
14
15static inline unsigned int bcd2bin(u8 val)
16{
17 return ((val) & 0x0f) + ((val) >> 4) * 10;
18}
Stefan Roese5a44c602007-10-21 08:16:12 +020019
Albin Tonnerre8aca7202009-08-13 15:31:11 +020020static inline u8 bin2bcd (unsigned int val)
21{
22 return (((val / 10) << 4) | (val % 10));
23}
Stefan Roese5a44c602007-10-21 08:16:12 +020024
25#endif /* _BCD_H */