xref: /linux/lib/bcd.c (revision 3a39d672e7f48b8d6b91a09afa4b55352773b4b5)
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/bcd.h>
3 #include <linux/export.h>
4 
_bcd2bin(unsigned char val)5 unsigned _bcd2bin(unsigned char val)
6 {
7 	return (val & 0x0f) + (val >> 4) * 10;
8 }
9 EXPORT_SYMBOL(_bcd2bin);
10 
_bin2bcd(unsigned val)11 unsigned char _bin2bcd(unsigned val)
12 {
13 	const unsigned int t = (val * 103) >> 10;
14 
15 	return (t << 4) | (val - t * 10);
16 }
17 EXPORT_SYMBOL(_bin2bcd);
18