summaryrefslogtreecommitdiff
path: root/src/commonlib/bsd/include
diff options
context:
space:
mode:
Diffstat (limited to 'src/commonlib/bsd/include')
-rw-r--r--src/commonlib/bsd/include/commonlib/bsd/bcd.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/commonlib/bsd/include/commonlib/bsd/bcd.h b/src/commonlib/bsd/include/commonlib/bsd/bcd.h
new file mode 100644
index 0000000000..6346b5f72f
--- /dev/null
+++ b/src/commonlib/bsd/include/commonlib/bsd/bcd.h
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+
+#ifndef _BCD_H_
+#define _BCD_H_
+
+#include <stdint.h>
+
+static inline uint8_t bcd2bin(uint8_t val)
+{
+ return ((val >> 4) & 0xf) * 10 + (val & 0xf);
+}
+
+static inline uint8_t bin2bcd(uint8_t val)
+{
+ return ((val / 10) << 4) | (val % 10);
+}
+
+#endif /* _BCD_H_ */