libosmocore  UNKNOWN
Osmocom core library
bitvec.h
Go to the documentation of this file.
1 #pragma once
2 
3 /* bit vector utility routines */
4 
5 /* (C) 2009 by Harald Welte <laforge@gnumonks.org>
6  *
7  * All Rights Reserved
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  *
23  */
24 
33 #include <stdint.h>
34 
39 enum bit_value {
40  ZERO = 0,
41  ONE = 1,
42  L = 2,
43  H = 3,
44 };
45 
47 struct bitvec {
48  unsigned int cur_bit;
49  unsigned int data_len;
50  uint8_t *data;
51 };
52 
53 enum bit_value bitvec_get_bit_pos(const struct bitvec *bv, unsigned int bitnr);
54 enum bit_value bitvec_get_bit_pos_high(const struct bitvec *bv,
55  unsigned int bitnr);
56 unsigned int bitvec_get_nth_set_bit(const struct bitvec *bv, unsigned int n);
57 int bitvec_set_bit_pos(struct bitvec *bv, unsigned int bitnum,
58  enum bit_value bit);
59 int bitvec_set_bit(struct bitvec *bv, enum bit_value bit);
60 int bitvec_get_bit_high(struct bitvec *bv);
61 int bitvec_set_bits(struct bitvec *bv, enum bit_value *bits, int count);
62 int bitvec_set_uint(struct bitvec *bv, unsigned int in, int count);
63 int bitvec_get_uint(struct bitvec *bv, int num_bits);
64 int bitvec_find_bit_pos(const struct bitvec *bv, unsigned int n, enum bit_value val);
65 int bitvec_spare_padding(struct bitvec *bv, unsigned int up_to_bit);
66 
int bitvec_get_bit_high(struct bitvec *bv)
get the next bit (low/high) inside a bitvec
Definition: bitvec.c:175
A CSN.1 &quot;L&quot; bit.
Definition: bitvec.h:42
int bitvec_get_uint(struct bitvec *bv, int num_bits)
get multiple bits (based on numeric value) from current pos
Definition: bitvec.c:222
int bitvec_set_bit_pos(struct bitvec *bv, unsigned int bitnum, enum bit_value bit)
set a bit at given position in a bit vector
Definition: bitvec.c:138
unsigned int data_len
length of data array in bytes
Definition: bitvec.h:49
A one (1) bit.
Definition: bitvec.h:41
bit_value
A single GSM bit.
Definition: bitvec.h:39
structure describing a bit vector
Definition: bitvec.h:47
enum bit_value bitvec_get_bit_pos(const struct bitvec *bv, unsigned int bitnr)
check if the bit is 0 or 1 for a given position inside a bitvec
Definition: bitvec.c:74
unsigned int cur_bit
cursor to the next unused bit
Definition: bitvec.h:48
int bitvec_set_bit(struct bitvec *bv, enum bit_value bit)
set the next bit inside a bitvec
Definition: bitvec.c:163
uint8_t * data
pointer to data array
Definition: bitvec.h:50
int bitvec_spare_padding(struct bitvec *bv, unsigned int up_to_bit)
pad all remaining bits up to num_bits
Definition: bitvec.c:240
int bitvec_set_bits(struct bitvec *bv, enum bit_value *bits, int count)
set multiple bits (based on array of bitvals) at current pos
Definition: bitvec.c:191
A CSN.1 &quot;H&quot; bit.
Definition: bitvec.h:43
int bitvec_set_uint(struct bitvec *bv, unsigned int in, int count)
set multiple bits (based on numeric value) at current pos
Definition: bitvec.c:205
unsigned int bitvec_get_nth_set_bit(const struct bitvec *bv, unsigned int n)
get the Nth set bit inside the bit vector
Definition: bitvec.c:118
enum bit_value bitvec_get_bit_pos_high(const struct bitvec *bv, unsigned int bitnr)
check if the bit is L or H for a given position inside a bitvec
Definition: bitvec.c:95
A zero (0) bit.
Definition: bitvec.h:40
int bitvec_find_bit_pos(const struct bitvec *bv, unsigned int n, enum bit_value val)
find first bit set in bit vector
Definition: bitvec.c:251