From fd11cae7be5bebcae0e4483a532f407e362f1a11 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 14 Jan 2021 19:32:18 +0100 Subject: [PATCH] printer: helper macros --- serviceinterface/ServiceInterfacePrinter.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/serviceinterface/ServiceInterfacePrinter.h b/serviceinterface/ServiceInterfacePrinter.h index fbdccdd1..e898adf6 100644 --- a/serviceinterface/ServiceInterfacePrinter.h +++ b/serviceinterface/ServiceInterfacePrinter.h @@ -2,6 +2,20 @@ #include #endif +//! https://stackoverflow.com/questions/111928/is-there-a-printf-converter-to-print-in-binary-format +//! Can be used to print out binary numbers in human-readable format. +#define BYTE_TO_BINARY_PATTERN "%c%c%c%c%c%c%c%c" +#define BYTE_TO_BINARY(byte) \ + (byte & 0x80 ? '1' : '0'), \ + (byte & 0x40 ? '1' : '0'), \ + (byte & 0x20 ? '1' : '0'), \ + (byte & 0x10 ? '1' : '0'), \ + (byte & 0x08 ? '1' : '0'), \ + (byte & 0x04 ? '1' : '0'), \ + (byte & 0x02 ? '1' : '0'), \ + (byte & 0x01 ? '1' : '0') + + namespace sif { enum PrintLevel {