libosmocore
0.6.3
Osmocom core library
Main Page
Modules
Data Structures
Files
File List
Globals
bits.h
Go to the documentation of this file.
1
#ifndef _OSMO_BITS_H
2
#define _OSMO_BITS_H
3
4
#include <stdint.h>
5
14
typedef
int8_t
sbit_t
;
15
typedef
uint8_t
ubit_t
;
16
typedef
uint8_t
pbit_t
;
18
/*
19
NOTE on the endianess of pbit_t:
20
Bits in a pbit_t are ordered MSB first, i.e. 0x80 is the first bit.
21
Bit i in a pbit_t array is array[i/8] & (1<<(7-i%8))
22
*/
23
27
static
inline
unsigned
int
osmo_pbit_bytesize
(
unsigned
int
num_bits)
28
{
29
unsigned
int
pbit_bytesize = num_bits / 8;
30
31
if
(num_bits % 8)
32
pbit_bytesize++;
33
34
return
pbit_bytesize;
35
}
36
37
int
osmo_ubit2pbit
(
pbit_t
*out,
const
ubit_t
*in,
unsigned
int
num_bits);
38
39
int
osmo_pbit2ubit
(
ubit_t
*out,
const
pbit_t
*in,
unsigned
int
num_bits);
40
41
int
osmo_ubit2pbit_ext
(
pbit_t
*out,
unsigned
int
out_ofs,
42
const
ubit_t
*in,
unsigned
int
in_ofs,
43
unsigned
int
num_bits,
int
lsb_mode);
44
45
int
osmo_pbit2ubit_ext
(
ubit_t
*out,
unsigned
int
out_ofs,
46
const
pbit_t
*in,
unsigned
int
in_ofs,
47
unsigned
int
num_bits,
int
lsb_mode);
48
49
50
/* BIT REVERSAL */
51
53
enum
osmo_br_mode
{
55
OSMO_BR_BITS_IN_DWORD
= 31,
57
OSMO_BR_BYTES_IN_DWORD
= 24,
59
OSMO_BR_BITS_IN_BYTE
= 7,
61
OSMO_BR_WORD_SWAP
= 16,
62
};
63
65
uint32_t
osmo_bit_reversal
(uint32_t x,
enum
osmo_br_mode
k);
66
67
/* \brief reverse the bits within each byte of a 32bit word */
68
uint32_t
osmo_revbytebits_32
(uint32_t x);
69
70
/* \brief reverse the bits within a byte */
71
uint32_t
osmo_revbytebits_8
(uint8_t x);
72
73
/* \brief reverse the bits of each byte in a given buffer */
74
void
osmo_revbytebits_buf
(uint8_t *buf,
int
len);
75
78
#endif
/* _OSMO_BITS_H */
include
osmocom
core
bits.h
Generated on Fri Aug 23 2013 20:51:42 for libosmocore by
1.8.1.2