Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _BCD_H
0003 #define _BCD_H
0004 
0005 #include <linux/compiler.h>
0006 
0007 #define bcd2bin(x)                  \
0008         (__builtin_constant_p((u8 )(x)) ?   \
0009         const_bcd2bin(x) :          \
0010         _bcd2bin(x))
0011 
0012 #define bin2bcd(x)                  \
0013         (__builtin_constant_p((u8 )(x)) ?   \
0014         const_bin2bcd(x) :          \
0015         _bin2bcd(x))
0016 
0017 #define const_bcd2bin(x)    (((x) & 0x0f) + ((x) >> 4) * 10)
0018 #define const_bin2bcd(x)    ((((x) / 10) << 4) + (x) % 10)
0019 
0020 unsigned _bcd2bin(unsigned char val) __attribute_const__;
0021 unsigned char _bin2bcd(unsigned val) __attribute_const__;
0022 
0023 #endif /* _BCD_H */