diff --git a/include/common/tdataformat.h b/include/common/tdataformat.h index 93a693cea9..bc29f3b59c 100644 --- a/include/common/tdataformat.h +++ b/include/common/tdataformat.h @@ -48,12 +48,12 @@ const static uint8_t BIT2_MAP[4][4] = {{0b00000000, 0b00000001, 0b00000010, 0}, {0b00001111, 0b00011111, 0b00101111, 4}, {0b00111111, 0b01111111, 0b10111111, 6}}; -#define BIT1_SIZE(n) (((n)-1) / 8 + 1) -#define BIT2_SIZE(n) (((n)-1) / 4 + 1) -#define SET_BIT1(p, i, v) ((p)[(i) / 8] &= BIT1_MAP[(i) % 8][v]) -#define GET_BIT1(p, i) (((p)[(i) / 8] >> ((i) % 8)) & ((uint8_t)1)) -#define SET_BIT2(p, i, v) ((p)[(i) / 4] &= BIT2_MAP[(i) % 4][v]) -#define GET_BIT2(p, i) (((p)[(i) / 4] >> BIT2_MAP[(i) % 4][3]) & ((uint8_t)3)) +#define BIT1_SIZE(n) (((n)-1) >> 3 + 1) +#define BIT2_SIZE(n) (((n)-1) >> 2 + 1) +#define SET_BIT1(p, i, v) ((p)[(i) >> 3] &= BIT1_MAP[(i)&7][v]) +#define GET_BIT1(p, i) (((p)[(i) >> 3] >> ((i)&7)) & ((uint8_t)1)) +#define SET_BIT2(p, i, v) ((p)[(i) >> 2] &= BIT2_MAP[(i)&3][v]) +#define GET_BIT2(p, i) (((p)[(i) >> 2] >> BIT2_MAP[(i)&3][3]) & ((uint8_t)3)) // STSchema int32_t tTSchemaCreate(int32_t sver, SSchema *pSchema, int32_t nCols, STSchema **ppTSchema);