aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2011-01-19 10:10:16 +0100
committerHarald Welte <laforge@gnumonks.org>2011-01-19 10:10:16 +0100
commit2230c133a69e8f9660051aff61626996deba4ed8 (patch)
tree9475e8a923355e5741ecebf5c8180005ca8b0d63 /include
parentc035ec63f509573408069340b4d40a906a40b8f7 (diff)
[BITS] introduce new packed/unpacked bit conversion routines
Diffstat (limited to 'include')
-rw-r--r--include/osmocore/Makefile.am2
-rw-r--r--include/osmocore/bits.h27
2 files changed, 28 insertions, 1 deletions
diff --git a/include/osmocore/Makefile.am b/include/osmocore/Makefile.am
index 2efaa96b..a3b12ef4 100644
--- a/include/osmocore/Makefile.am
+++ b/include/osmocore/Makefile.am
@@ -1,4 +1,4 @@
-osmocore_HEADERS = signal.h linuxlist.h timer.h select.h msgb.h \
+osmocore_HEADERS = signal.h linuxlist.h timer.h select.h msgb.h bits.h \
tlv.h bitvec.h comp128.h statistics.h gsm_utils.h utils.h \
gsmtap.h write_queue.h rsl.h gsm48.h rxlev_stat.h mncc.h \
gsm48_ie.h logging.h gsm0808.h rate_ctr.h gsmtap_util.h \
diff --git a/include/osmocore/bits.h b/include/osmocore/bits.h
new file mode 100644
index 00000000..662c4a9d
--- /dev/null
+++ b/include/osmocore/bits.h
@@ -0,0 +1,27 @@
+#ifndef _OSMO_BITS_H
+#define _OSMO_BITS_H
+
+#include <stdint.h>
+
+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) */
+
+/* determine how many bytes we would need for 'num_bits' packed bits */
+static inline unsigned int osmo_pbit_bytesize(unsigned int num_bits)
+{
+ unsigned int pbit_bytesize = num_bits / 8;
+
+ if (num_bits % 8)
+ pbit_bytesize++;
+
+ return pbit_bytesize;
+}
+
+/* convert unpacked bits to packed bits, return length in bytes */
+int osmo_ubit2pbit(pbit_t *out, const ubit_t *in, unsigned int num_bits);
+
+/* convert packed bits to unpacked bits, return length in bytes */
+int osmo_pbit2ubit(ubit_t *out, const pbit_t *in, unsigned int num_bits);
+
+#endif