libosmocore
0.9.3
Osmocom core library
Main Page
Modules
Data Structures
Files
File List
Globals
bits.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <stdint.h>
4
#include <stddef.h>
5
6
#include <osmocom/core/bit16gen.h>
7
#include <osmocom/core/bit32gen.h>
8
#include <osmocom/core/bit64gen.h>
9
18
typedef
int8_t
sbit_t
;
19
typedef
uint8_t
ubit_t
;
20
typedef
uint8_t
pbit_t
;
22
/*
23
NOTE on the endianess of pbit_t:
24
Bits in a pbit_t are ordered MSB first, i.e. 0x80 is the first bit.
25
Bit i in a pbit_t array is array[i/8] & (1<<(7-i%8))
26
*/
27
31
static
inline
unsigned
int
osmo_pbit_bytesize
(
unsigned
int
num_bits)
32
{
33
unsigned
int
pbit_bytesize = num_bits / 8;
34
35
if
(num_bits % 8)
36
pbit_bytesize++;
37
38
return
pbit_bytesize;
39
}
40
41
int
osmo_ubit2pbit
(
pbit_t
*out,
const
ubit_t
*in,
unsigned
int
num_bits);
42
43
int
osmo_pbit2ubit
(
ubit_t
*out,
const
pbit_t
*in,
unsigned
int
num_bits);
44
45
int
osmo_ubit2pbit_ext
(
pbit_t
*out,
unsigned
int
out_ofs,
46
const
ubit_t
*in,
unsigned
int
in_ofs,
47
unsigned
int
num_bits,
int
lsb_mode);
48
49
int
osmo_pbit2ubit_ext
(
ubit_t
*out,
unsigned
int
out_ofs,
50
const
pbit_t
*in,
unsigned
int
in_ofs,
51
unsigned
int
num_bits,
int
lsb_mode);
52
53
54
/* BIT REVERSAL */
55
57
enum
osmo_br_mode
{
59
OSMO_BR_BITS_IN_DWORD
= 31,
61
OSMO_BR_BYTES_IN_DWORD
= 24,
63
OSMO_BR_BITS_IN_BYTE
= 7,
65
OSMO_BR_WORD_SWAP
= 16,
66
};
67
69
uint32_t
osmo_bit_reversal
(uint32_t x,
enum
osmo_br_mode
k);
70
71
/* \brief reverse the bits within each byte of a 32bit word */
72
uint32_t
osmo_revbytebits_32
(uint32_t x);
73
74
/* \brief reverse the bits within a byte */
75
uint32_t
osmo_revbytebits_8
(uint8_t x);
76
77
/* \brief reverse the bits of each byte in a given buffer */
78
void
osmo_revbytebits_buf
(uint8_t *buf,
int
len);
79
85
static
inline
uint16_t
osmo_rol16
(uint16_t in,
unsigned
shift)
86
{
87
return
(in << shift) | (in >> (16 - shift));
88
}
89
include
osmocom
core
bits.h
Generated on Mon Jan 18 2016 13:17:40 for libosmocore by
1.8.1.2