bitvec.h
Go to the documentation of this file.
#pragma once
/* bit vector utility routines */
/* (C) 2009 by Harald Welte <laforge@gnumonks.org>
*
* All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#include <stdint.h>
enum bit_value {
ZERO = 0,
ONE = 1,
L = 2,
H = 3,
};
struct bitvec {
unsigned int cur_bit;
unsigned int data_len;
uint8_t *data;
};
enum bit_value bitvec_get_bit_pos(const struct bitvec *bv, unsigned int bitnr);
enum bit_value bitvec_get_bit_pos_high(const struct bitvec *bv,
unsigned int bitnr);
unsigned int bitvec_get_nth_set_bit(const struct bitvec *bv, unsigned int n);
int bitvec_set_bit_pos(struct bitvec *bv, unsigned int bitnum,
enum bit_value bit);
int bitvec_set_bit(struct bitvec *bv, enum bit_value bit);
int bitvec_get_bit_high(struct bitvec *bv);
int bitvec_set_bits(struct bitvec *bv, enum bit_value *bits, int count);
int bitvec_set_uint(struct bitvec *bv, unsigned int in, int count);
int bitvec_get_uint(struct bitvec *bv, int num_bits);
int bitvec_find_bit_pos(const struct bitvec *bv, unsigned int n, enum bit_value val);
int bitvec_spare_padding(struct bitvec *bv, unsigned int up_to_bit);
bitvec_get_bit_high
int bitvec_get_bit_high(struct bitvec *bv)
get the next bit (low/high) inside a bitvec
Definition: bitvec.c:175
L
A CSN.1 "L" bit.
Definition: bitvec.h:42
bitvec_get_uint
int bitvec_get_uint(struct bitvec *bv, int num_bits)
get multiple bits (based on numeric value) from current pos
Definition: bitvec.c:222
bitvec_set_bit_pos
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
bitvec::data_len
unsigned int data_len
length of data array in bytes
Definition: bitvec.h:49
ONE
A one (1) bit.
Definition: bitvec.h:41
bit_value
bit_value
A single GSM bit.
Definition: bitvec.h:39
bitvec
structure describing a bit vector
Definition: bitvec.h:47
bitvec_get_bit_pos
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
bitvec::cur_bit
unsigned int cur_bit
cursor to the next unused bit
Definition: bitvec.h:48
bitvec_set_bit
int bitvec_set_bit(struct bitvec *bv, enum bit_value bit)
set the next bit inside a bitvec
Definition: bitvec.c:163
bitvec::data
uint8_t * data
pointer to data array
Definition: bitvec.h:50
bitvec_spare_padding
int bitvec_spare_padding(struct bitvec *bv, unsigned int up_to_bit)
pad all remaining bits up to num_bits
Definition: bitvec.c:240
bitvec_set_bits
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
H
A CSN.1 "H" bit.
Definition: bitvec.h:43
bitvec_set_uint
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
bitvec_get_nth_set_bit
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
bitvec_get_bit_pos_high
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
ZERO
A zero (0) bit.
Definition: bitvec.h:40
bitvec_find_bit_pos
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