summaryrefslogtreecommitdiffstats
path: root/qemu/include/qemu/bcd.h
diff options
context:
space:
mode:
Diffstat (limited to 'qemu/include/qemu/bcd.h')
-rw-r--r--qemu/include/qemu/bcd.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/qemu/include/qemu/bcd.h b/qemu/include/qemu/bcd.h
new file mode 100644
index 000000000..b4c9b64b8
--- /dev/null
+++ b/qemu/include/qemu/bcd.h
@@ -0,0 +1,15 @@
+#ifndef QEMU_BCD_H
+#define QEMU_BCD_H 1
+
+/* Convert a byte between binary and BCD. */
+static inline uint8_t to_bcd(uint8_t val)
+{
+ return ((val / 10) << 4) | (val % 10);
+}
+
+static inline uint8_t from_bcd(uint8_t val)
+{
+ return ((val >> 4) * 10) + (val & 0x0f);
+}
+
+#endif