blob: eb2cbcbaf98d9f61c3a15a2303135b1e9938dd65 [file] [log] [blame]
Harald Welte2230c132011-01-19 10:10:16 +01001#ifndef _OSMO_BITS_H
2#define _OSMO_BITS_H
3
4#include <stdint.h>
5
6typedef uint8_t sbit_t; /* soft bit (-127...127) */
7typedef uint8_t ubit_t; /* unpacked bit (0 or 1) */
8typedef uint8_t pbit_t; /* packed bis (8 bits in a byte) */
9
10/* determine how many bytes we would need for 'num_bits' packed bits */
11static inline unsigned int osmo_pbit_bytesize(unsigned int num_bits)
12{
13 unsigned int pbit_bytesize = num_bits / 8;
14
15 if (num_bits % 8)
16 pbit_bytesize++;
17
18 return pbit_bytesize;
19}
20
21/* convert unpacked bits to packed bits, return length in bytes */
22int osmo_ubit2pbit(pbit_t *out, const ubit_t *in, unsigned int num_bits);
23
24/* convert packed bits to unpacked bits, return length in bytes */
25int osmo_pbit2ubit(ubit_t *out, const pbit_t *in, unsigned int num_bits);
26
Sylvain Munautaeb10772011-01-21 12:22:30 +010027/* convert unpacked bits to packed bits (extended options but slower),
28 * return length in bytes (max written ofs of output buffer + 1) */
29int osmo_ubit2pbit_ext(pbit_t *out, unsigned int out_ofs,
30 const ubit_t *in, unsigned int in_ofs,
31 unsigned int num_bits, int lsb_mode);
32
33/* convert packed bits to unpacked bits (extended options but slower),
34 * return length in bytes (max written ofs of output buffer + 1) */
35int osmo_pbit2ubit_ext(ubit_t *out, unsigned int out_ofs,
36 const pbit_t *in, unsigned int in_ofs,
37 unsigned int num_bits, int lsb_mode);
38
Harald Welte2230c132011-01-19 10:10:16 +010039#endif