libosmocore  0.9.0
Osmocom core library
Bit vectors

Files

file  bitvec.h
 Osmocom bit vector abstraction.
 
file  bitvec.c
 Osmocom bit vector abstraction.
 

Data Structures

struct  bitvec
 structure describing a bit vector More...
 

Macros

#define BITNUM_FROM_COMP(byte, bit)   ((byte*8)+bit)
 

Enumerations

enum  bit_value { ZERO = 0, ONE = 1, L = 2, H = 3 }
 A single GSM bit. More...
 

Functions

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 More...
 
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 More...
 
unsigned int bitvec_get_nth_set_bit (const struct bitvec *bv, unsigned int n)
 get the Nth set bit inside the bit vector More...
 
int bitvec_set_bit_pos (struct bitvec *bv, unsigned int bitnr, enum bit_value bit)
 set a bit at given position in a bit vector More...
 
int bitvec_set_bit (struct bitvec *bv, enum bit_value bit)
 set the next bit inside a bitvec More...
 
int bitvec_get_bit_high (struct bitvec *bv)
 get the next bit (low/high) inside a bitvec
 
int bitvec_set_bits (struct bitvec *bv, enum bit_value *bits, int count)
 set multiple bits (based on array of bitvals) at current pos More...
 
int bitvec_set_uint (struct bitvec *bv, unsigned int ui, int num_bits)
 set multiple bits (based on numeric value) at current pos
 
int bitvec_get_uint (struct bitvec *bv, int num_bits)
 get multiple bits (based on numeric value) from current pos
 
int bitvec_find_bit_pos (const struct bitvec *bv, unsigned int n, enum bit_value val)
 find first bit set in bit vector
 
int bitvec_spare_padding (struct bitvec *bv, unsigned int up_to_bit)
 pad all remaining bits up to num_bits
 
static unsigned int bytenum_from_bitnum (unsigned int bitnum)
 
static uint8_t bitval2mask (enum bit_value bit, uint8_t bitnum)
 

Detailed Description

Enumeration Type Documentation

§ bit_value

enum bit_value

A single GSM bit.

In GSM mac blocks, every bit can be 0 or 1, or L or H. L/H are defined relative to the 0x2b padding pattern

Enumerator
ZERO 

A zero (0) bit.

ONE 

A one (1) bit.

A CSN.1 "L" bit.

A CSN.1 "H" bit.

Function Documentation

§ 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

Parameters
[in]bvthe bit vector on which to check
[in]bitnrthe bit number inside the bit vector to check
Returns

Referenced by bitvec_find_bit_pos(), bitvec_get_nth_set_bit(), and bitvec_get_uint().

§ 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

Parameters
[in]bvthe bit vector on which to check
[in]bitnrthe bit number inside the bit vector to check

Referenced by bitvec_get_bit_high().

§ 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

Parameters
[in]bvthe bit vector to use
[in]nthe bit number to get
Returns
the bit number (offset) of the Nth set bit in bv

References bitvec_get_bit_pos(), data_len, and ONE.

§ bitvec_set_bit()

int bitvec_set_bit ( struct bitvec bv,
enum bit_value  bit 
)

set the next bit inside a bitvec

Parameters
[in]bvbit vector to be used
[in]bitvalue of the bit to be set

References bitvec_set_bit_pos(), and cur_bit.

Referenced by bitvec_set_bits(), bitvec_set_uint(), and bitvec_spare_padding().

§ bitvec_set_bit_pos()

int bitvec_set_bit_pos ( struct bitvec bv,
unsigned int  bitnr,
enum bit_value  bit 
)

set a bit at given position in a bit vector

Parameters
[in]bvbit vector on which to operate
[in]bitnrnumber of bit to be set
[in]bitvalue to which the bit is to be set

Referenced by bitvec_set_bit().

§ 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

Parameters
[in]bvbit vector
[in]bitsarray of bit_value
[in]countnumber of bits to set

References bitvec_set_bit().