aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/osmocore/bits.h6
-rw-r--r--src/bits.c2
2 files changed, 7 insertions, 1 deletions
diff --git a/include/osmocore/bits.h b/include/osmocore/bits.h
index eb2cbcba..8d4a0789 100644
--- a/include/osmocore/bits.h
+++ b/include/osmocore/bits.h
@@ -7,6 +7,12 @@ typedef uint8_t sbit_t; /* soft bit (-127...127) */
typedef uint8_t ubit_t; /* unpacked bit (0 or 1) */
typedef uint8_t pbit_t; /* packed bis (8 bits in a byte) */
+/*
+ NOTE on the endianess of pbit_t:
+ Bits in a pbit_t are ordered MSB first, i.e. 0x80 is the first bit.
+ Bit i in a pbit_t array is array[i/8] & (1<<(7-i%8))
+*/
+
/* determine how many bytes we would need for 'num_bits' packed bits */
static inline unsigned int osmo_pbit_bytesize(unsigned int num_bits)
{
diff --git a/src/bits.c b/src/bits.c
index 029cfe55..fcdf5cc3 100644
--- a/src/bits.c
+++ b/src/bits.c
@@ -15,7 +15,7 @@ int osmo_ubit2pbit(pbit_t *out, const ubit_t *in, unsigned int num_bits)
curbyte |= (in[i] << bitnum);
- if (i > 0 && i % 8 == 0) {
+ if(i % 8 == 7){
*outptr++ = curbyte;
curbyte = 0;
}