libosmocore
0.9.3.20160317
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
#define OSMO_BIN_SPEC "%d%d%d%d%d%d%d%d"
54
#define OSMO_BIN_PRINT(byte) \
55
(byte & 0x80 ? 1 : 0), \
56
(byte & 0x40 ? 1 : 0), \
57
(byte & 0x20 ? 1 : 0), \
58
(byte & 0x10 ? 1 : 0), \
59
(byte & 0x08 ? 1 : 0), \
60
(byte & 0x04 ? 1 : 0), \
61
(byte & 0x02 ? 1 : 0), \
62
(byte & 0x01 ? 1 : 0)
63
64
#define OSMO_BIT_SPEC "%c%c%c%c%c%c%c%c"
65
#define OSMO_BIT_PRINT(byte) \
66
(byte & 0x80 ? '1' : '.'), \
67
(byte & 0x40 ? '1' : '.'), \
68
(byte & 0x20 ? '1' : '.'), \
69
(byte & 0x10 ? '1' : '.'), \
70
(byte & 0x08 ? '1' : '.'), \
71
(byte & 0x04 ? '1' : '.'), \
72
(byte & 0x02 ? '1' : '.'), \
73
(byte & 0x01 ? '1' : '.')
74
75
/* BIT REVERSAL */
76
78
enum
osmo_br_mode
{
80
OSMO_BR_BITS_IN_DWORD
= 31,
82
OSMO_BR_BYTES_IN_DWORD
= 24,
84
OSMO_BR_BITS_IN_BYTE
= 7,
86
OSMO_BR_WORD_SWAP
= 16,
87
};
88
90
uint32_t
osmo_bit_reversal
(uint32_t x,
enum
osmo_br_mode
k);
91
92
/* \brief reverse the bits within each byte of a 32bit word */
93
uint32_t
osmo_revbytebits_32
(uint32_t x);
94
95
/* \brief reverse the bits within a byte */
96
uint32_t
osmo_revbytebits_8
(uint8_t x);
97
98
/* \brief reverse the bits of each byte in a given buffer */
99
void
osmo_revbytebits_buf
(uint8_t *buf,
int
len);
100
106
static
inline
uint16_t
osmo_rol16
(uint16_t in,
unsigned
shift)
107
{
108
return
(in << shift) | (in >> (16 - shift));
109
}
110
include
osmocom
core
bits.h
Generated on Thu Mar 17 2016 19:51:35 for libosmocore by
1.8.1.2