BCD cleanup

Combine multiple BCD implementations.

Signed-off-by: Paul Brook <paul@codesourcery.com>
diff --git a/qemu-common.h b/qemu-common.h
index b779cfe..b1e038b 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -248,6 +248,17 @@
 struct Monitor;
 typedef struct Monitor Monitor;
 
+/* 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);
+}
+
 #include "module.h"
 
 #endif /* dyngen-exec.h hack */