From 6a5ef46dd018c8e66e341a531403e40de24893f2 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 24 Feb 2016 16:05:48 +0100 Subject: Add byte printing macros It's sometimes handy for debugging to be able to immediately see which bits are set in a given byte. Generalize macro used for that in bitvec tests and make it available for the rest of the library. --- include/osmocom/core/bits.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'include/osmocom/core') diff --git a/include/osmocom/core/bits.h b/include/osmocom/core/bits.h index 1587b050..46f0c8b8 100644 --- a/include/osmocom/core/bits.h +++ b/include/osmocom/core/bits.h @@ -50,6 +50,27 @@ int osmo_pbit2ubit_ext(ubit_t *out, unsigned int out_ofs, const pbit_t *in, unsigned int in_ofs, unsigned int num_bits, int lsb_mode); +#define OSMO_BIN_SPEC "%d%d%d%d%d%d%d%d" +#define OSMO_BIN_PRINT(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) + +#define OSMO_BIT_SPEC "%c%c%c%c%c%c%c%c" +#define OSMO_BIT_PRINT(byte) \ + (byte & 0x80 ? '1' : '.'), \ + (byte & 0x40 ? '1' : '.'), \ + (byte & 0x20 ? '1' : '.'), \ + (byte & 0x10 ? '1' : '.'), \ + (byte & 0x08 ? '1' : '.'), \ + (byte & 0x04 ? '1' : '.'), \ + (byte & 0x02 ? '1' : '.'), \ + (byte & 0x01 ? '1' : '.') /* BIT REVERSAL */ -- cgit v1.2.3