diff options
author | Max <msuraev@sysmocom.de> | 2016-02-24 16:05:48 +0100 |
---|---|---|
committer | Holger Hans Peter Freyther <holger@moiji-mobile.com> | 2016-02-25 22:35:44 +0100 |
commit | 6a5ef46dd018c8e66e341a531403e40de24893f2 (patch) | |
tree | 58b1fd6b36b0939028c7395d5c943d517d901787 /include/osmocom/core | |
parent | f81eb328b61f65a09b7233aaa70b2f655c0300bc (diff) |
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.
Diffstat (limited to 'include/osmocom/core')
-rw-r--r-- | include/osmocom/core/bits.h | 21 |
1 files changed, 21 insertions, 0 deletions
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 */ |