diff options
-rw-r--r-- | include/osmocom/core/bits.h | 21 | ||||
-rw-r--r-- | tests/bitvec/bitvec_test.c | 13 |
2 files changed, 22 insertions, 12 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 */ diff --git a/tests/bitvec/bitvec_test.c b/tests/bitvec/bitvec_test.c index 800a0406..76d6773e 100644 --- a/tests/bitvec/bitvec_test.c +++ b/tests/bitvec/bitvec_test.c @@ -11,17 +11,6 @@ #include <osmocom/core/bitvec.h> #include <osmocom/core/bits.h> -#define BIN_PATTERN "%d%d%d%d%d%d%d%d" -#define BIN(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) - static char lol[1024]; // we pollute this with printed vectors static inline void test_rl(const struct bitvec *bv) { @@ -45,7 +34,7 @@ static inline void test_get(struct bitvec *bv, unsigned n) int16_t x = bitvec_get_int16_msb(bv, n); uint8_t tmp[2]; osmo_store16be(x, &tmp); - printf(" -> %d (%u bit) ["BIN_PATTERN" "BIN_PATTERN"]:\n", x, n, BIN(tmp[0]), BIN(tmp[1])); + printf(" -> %d (%u bit) ["OSMO_BIN_SPEC" "OSMO_BIN_SPEC"]:\n", x, n, OSMO_BIN_PRINT(tmp[0]), OSMO_BIN_PRINT(tmp[1])); bitvec_to_string_r(bv, lol); printf("%s [%d]\n", lol, bv->cur_bit); } |