From abd0c6bda0c89f36528e1a7efac99277607a5280 Mon Sep 17 00:00:00 2001 From: Paul Brook Date: Fri, 20 Nov 2009 00:03:47 +0000 Subject: BCD cleanup Combine multiple BCD implementations. Signed-off-by: Paul Brook --- qemu-common.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'qemu-common.h') 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 @@ void qemu_iovec_from_buffer(QEMUIOVector *qiov, const void *buf, size_t count); 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 */ -- cgit v1.1