ubit2pbit flushes at the wrong moment, added one note to bits.h
authorChristian Vogel <vogelchr@vogel.cx>
Sat, 22 Jan 2011 21:48:37 +0000 (22:48 +0100)
committerChristian Vogel <vogelchr@vogel.cx>
Sat, 22 Jan 2011 21:48:37 +0000 (22:48 +0100)
(e.g. input2[] test sequence from testra/crc_test
 decodes incorrectly to packed bits: 90 b0 3e 80 03 87 53 bd 6f 08,
 this patch fixes it)

include/osmocore/bits.h
src/bits.c

index eb2cbcb..8d4a078 100644 (file)
@@ -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)
 {
index 029cfe5..fcdf5cc 100644 (file)
@@ -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;
                }