\doxysection{include/osmocom/core/bits.h File Reference}
\label{bits_8h}\index{include/osmocom/core/bits.h@{include/osmocom/core/bits.h}}


Osmocom bit level support code.  


{\ttfamily \#include $<$stdint.\+h$>$}\newline
{\ttfamily \#include $<$stddef.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/core/bit16gen.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/core/bit32gen.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/core/bit64gen.\+h$>$}\newline
\doxysubsection*{Macros}
\begin{DoxyCompactItemize}
\item 
\#define \textbf{ OSMO\+\_\+\+BIN\+\_\+\+SPEC}~\char`\"{}\%d\%d\%d\%d\%d\%d\%d\%d\char`\"{}
\item 
\#define \textbf{ OSMO\+\_\+\+BIN\+\_\+\+PRINT}(byte)
\item 
\#define \textbf{ OSMO\+\_\+\+BIT\+\_\+\+SPEC}~\char`\"{}\%c\%\textbf{ c}\%\textbf{ c}\%\textbf{ c}\%\textbf{ c}\%\textbf{ c}\%\textbf{ c}\%\textbf{ c}\char`\"{}
\item 
\#define \textbf{ OSMO\+\_\+\+BIT\+\_\+\+PRINT\+\_\+\+EX}(byte,  ch)
\item 
\#define \textbf{ OSMO\+\_\+\+BIT\+\_\+\+PRINT}(byte)~\textbf{ OSMO\+\_\+\+BIT\+\_\+\+PRINT\+\_\+\+EX}(byte, \textquotesingle{}1\textquotesingle{})
\end{DoxyCompactItemize}
\doxysubsection*{Typedefs}
\begin{DoxyCompactItemize}
\item 
typedef int8\+\_\+t \textbf{ sbit\+\_\+t}
\begin{DoxyCompactList}\small\item\em soft bit with value (-\/127...127), as commonly used in communications receivers such as [viterbi] decoders \end{DoxyCompactList}\item 
typedef uint8\+\_\+t \textbf{ ubit\+\_\+t}
\begin{DoxyCompactList}\small\item\em unpacked bit (0 or 1)\+: 1 bit per byte \end{DoxyCompactList}\item 
typedef uint8\+\_\+t \textbf{ pbit\+\_\+t}
\begin{DoxyCompactList}\small\item\em packed bits (8 bits in a byte). \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Enumerations}
\begin{DoxyCompactItemize}
\item 
enum \textbf{ osmo\+\_\+br\+\_\+mode} \{ \newline
\textbf{ OSMO\+\_\+\+BR\+\_\+\+BITS\+\_\+\+IN\+\_\+\+DWORD} = 31
, \newline
\textbf{ OSMO\+\_\+\+BR\+\_\+\+BYTES\+\_\+\+IN\+\_\+\+DWORD} = 24
, \newline
\textbf{ OSMO\+\_\+\+BR\+\_\+\+BITS\+\_\+\+IN\+\_\+\+BYTE} = 7
, \newline
\textbf{ OSMO\+\_\+\+BR\+\_\+\+WORD\+\_\+\+SWAP} = 16
 \}
\begin{DoxyCompactList}\small\item\em bit-\/reversal mode for \doxyref{osmo\+\_\+bit\+\_\+reversal()}{p.}{group__bits_gae4f3c9fa5d7ac188213d59dd8f83da40} \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Functions}
\begin{DoxyCompactItemize}
\item 
static unsigned int \textbf{ osmo\+\_\+pbit\+\_\+bytesize} (unsigned int num\+\_\+bits)
\begin{DoxyCompactList}\small\item\em determine how many bytes we would need for {\itshape num\+\_\+bits} packed bits \end{DoxyCompactList}\item 
int \textbf{ osmo\+\_\+ubit2pbit} (\textbf{ pbit\+\_\+t} $\ast$out, const \textbf{ ubit\+\_\+t} $\ast$in, unsigned int num\+\_\+bits)
\begin{DoxyCompactList}\small\item\em convert unpacked bits to packed bits, return length in bytes \end{DoxyCompactList}\item 
int \textbf{ osmo\+\_\+pbit2ubit} (\textbf{ ubit\+\_\+t} $\ast$out, const \textbf{ pbit\+\_\+t} $\ast$in, unsigned int num\+\_\+bits)
\begin{DoxyCompactList}\small\item\em convert packed bits to unpacked bits, return length in bytes \end{DoxyCompactList}\item 
void \textbf{ osmo\+\_\+nibble\+\_\+shift\+\_\+right} (uint8\+\_\+t $\ast$out, const uint8\+\_\+t $\ast$in, unsigned int num\+\_\+nibbles)
\begin{DoxyCompactList}\small\item\em Shift unaligned input to octet-\/aligned output. \end{DoxyCompactList}\item 
void \textbf{ osmo\+\_\+nibble\+\_\+shift\+\_\+left\+\_\+unal} (uint8\+\_\+t $\ast$out, const uint8\+\_\+t $\ast$in, unsigned int num\+\_\+nibbles)
\begin{DoxyCompactList}\small\item\em Shift unaligned input to octet-\/aligned output. \end{DoxyCompactList}\item 
void \textbf{ osmo\+\_\+ubit2sbit} (\textbf{ sbit\+\_\+t} $\ast$out, const \textbf{ ubit\+\_\+t} $\ast$in, unsigned int num\+\_\+bits)
\begin{DoxyCompactList}\small\item\em convert unpacked bits to soft bits \end{DoxyCompactList}\item 
void \textbf{ osmo\+\_\+sbit2ubit} (\textbf{ ubit\+\_\+t} $\ast$out, const \textbf{ sbit\+\_\+t} $\ast$in, unsigned int num\+\_\+bits)
\begin{DoxyCompactList}\small\item\em convert soft bits to unpacked bits \end{DoxyCompactList}\item 
int \textbf{ osmo\+\_\+ubit2pbit\+\_\+ext} (\textbf{ pbit\+\_\+t} $\ast$out, unsigned int out\+\_\+ofs, const \textbf{ ubit\+\_\+t} $\ast$in, unsigned int in\+\_\+ofs, unsigned int num\+\_\+bits, int lsb\+\_\+mode)
\begin{DoxyCompactList}\small\item\em convert unpacked bits to packed bits (extended options) \end{DoxyCompactList}\item 
int \textbf{ osmo\+\_\+pbit2ubit\+\_\+ext} (\textbf{ ubit\+\_\+t} $\ast$out, unsigned int out\+\_\+ofs, const \textbf{ pbit\+\_\+t} $\ast$in, unsigned int in\+\_\+ofs, unsigned int num\+\_\+bits, int lsb\+\_\+mode)
\begin{DoxyCompactList}\small\item\em convert packed bits to unpacked bits (extended options) \end{DoxyCompactList}\item 
uint32\+\_\+t \textbf{ osmo\+\_\+bit\+\_\+reversal} (uint32\+\_\+t \textbf{ x}, enum \textbf{ osmo\+\_\+br\+\_\+mode} \textbf{ k})
\begin{DoxyCompactList}\small\item\em generalized bit reversal function \end{DoxyCompactList}\item 
uint32\+\_\+t \textbf{ osmo\+\_\+revbytebits\+\_\+32} (uint32\+\_\+t \textbf{ x})
\begin{DoxyCompactList}\small\item\em reverse the bit-\/order in each byte of a dword \end{DoxyCompactList}\item 
uint32\+\_\+t \textbf{ osmo\+\_\+revbytebits\+\_\+8} (uint8\+\_\+t \textbf{ x})
\begin{DoxyCompactList}\small\item\em reverse the bit order in a byte \end{DoxyCompactList}\item 
void \textbf{ osmo\+\_\+revbytebits\+\_\+buf} (uint8\+\_\+t $\ast$buf, int \textbf{ len})
\begin{DoxyCompactList}\small\item\em reverse bit-\/order of each byte in a buffer \end{DoxyCompactList}\item 
static uint16\+\_\+t \textbf{ osmo\+\_\+rol16} (uint16\+\_\+t in, unsigned shift)
\begin{DoxyCompactList}\small\item\em left circular shift \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Detailed Description}
Osmocom bit level support code. 

