\doxysection{soft, unpacked and packed bits}
\label{group__bits}\index{soft, unpacked and packed bits@{soft, unpacked and packed bits}}


Osmocom bit level support code.  


\doxysubsection*{Files}
\begin{DoxyCompactItemize}
\item 
file \textbf{ bits.\+h}
\begin{DoxyCompactList}\small\item\em Osmocom bit level support code. \end{DoxyCompactList}\item 
file \textbf{ bits.\+c}
\end{DoxyCompactItemize}
\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*{Variables}
\begin{DoxyCompactItemize}
\item 
static const uint8\+\_\+t \textbf{ flip\+\_\+table} [256]
\end{DoxyCompactItemize}


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

This module implements the notion of different bit-\/fields, such as
\begin{DoxyItemize}
\item unpacked bits (\doxyref{ubit\+\_\+t}{p.}{group__bits_ga6a432fe43b85ec8e0d13e7de04a3f8ed}), i.\+e. 1 bit per byte
\item packed bits (\doxyref{pbit\+\_\+t}{p.}{group__bits_ga1780d9a13fbdbf69eae79b53092e47db}), i.\+e. 8 bits per byte
\item soft bits (\doxyref{sbit\+\_\+t}{p.}{group__bits_gab6b2fe6d30b1abe4a655e9cf033b23ca}), 1 bit per byte from -\/127 to 127 
\end{DoxyItemize}

\doxysubsection{Macro Definition Documentation}
\mbox{\label{group__bits_gaf1796dd84e28e6cad4e792c886f491fc}} 
\index{soft, unpacked and packed bits@{soft, unpacked and packed bits}!OSMO\_BIN\_PRINT@{OSMO\_BIN\_PRINT}}
\index{OSMO\_BIN\_PRINT@{OSMO\_BIN\_PRINT}!soft, unpacked and packed bits@{soft, unpacked and packed bits}}
\doxysubsubsection{OSMO\_BIN\_PRINT}
{\footnotesize\ttfamily \#define OSMO\+\_\+\+BIN\+\_\+\+PRINT(\begin{DoxyParamCaption}\item[{}]{byte }\end{DoxyParamCaption})}

{\bfseries Value\+:}
\begin{DoxyCode}{0}
\DoxyCodeLine{  (\textcolor{keywordtype}{byte} \& 0x80 ? 1 : 0), \(\backslash\)}
\DoxyCodeLine{  (\textcolor{keywordtype}{byte} \& 0x40 ? 1 : 0), \(\backslash\)}
\DoxyCodeLine{  (\textcolor{keywordtype}{byte} \& 0x20 ? 1 : 0), \(\backslash\)}
\DoxyCodeLine{  (\textcolor{keywordtype}{byte} \& 0x10 ? 1 : 0), \(\backslash\)}
\DoxyCodeLine{  (\textcolor{keywordtype}{byte} \& 0x08 ? 1 : 0), \(\backslash\)}
\DoxyCodeLine{  (\textcolor{keywordtype}{byte} \& 0x04 ? 1 : 0), \(\backslash\)}
\DoxyCodeLine{  (\textcolor{keywordtype}{byte} \& 0x02 ? 1 : 0), \(\backslash\)}
\DoxyCodeLine{  (\textcolor{keywordtype}{byte} \& 0x01 ? 1 : 0)}

\end{DoxyCode}
\mbox{\label{group__bits_gab3ca2b9ae4ea991a847081d5c072fda8}} 
\index{soft, unpacked and packed bits@{soft, unpacked and packed bits}!OSMO\_BIN\_SPEC@{OSMO\_BIN\_SPEC}}
\index{OSMO\_BIN\_SPEC@{OSMO\_BIN\_SPEC}!soft, unpacked and packed bits@{soft, unpacked and packed bits}}
\doxysubsubsection{OSMO\_BIN\_SPEC}
{\footnotesize\ttfamily \#define OSMO\+\_\+\+BIN\+\_\+\+SPEC~\char`\"{}\%d\%d\%d\%d\%d\%d\%d\%d\char`\"{}}

\mbox{\label{group__bits_ga5b7bbe6c4df28755bded35dbcffda2eb}} 
\index{soft, unpacked and packed bits@{soft, unpacked and packed bits}!OSMO\_BIT\_PRINT@{OSMO\_BIT\_PRINT}}
\index{OSMO\_BIT\_PRINT@{OSMO\_BIT\_PRINT}!soft, unpacked and packed bits@{soft, unpacked and packed bits}}
\doxysubsubsection{OSMO\_BIT\_PRINT}
{\footnotesize\ttfamily \#define OSMO\+\_\+\+BIT\+\_\+\+PRINT(\begin{DoxyParamCaption}\item[{}]{byte }\end{DoxyParamCaption})~\textbf{ OSMO\+\_\+\+BIT\+\_\+\+PRINT\+\_\+\+EX}(byte, \textquotesingle{}1\textquotesingle{})}

\mbox{\label{group__bits_ga71e06d05678a8e41476c648bfc26a35b}} 
\index{soft, unpacked and packed bits@{soft, unpacked and packed bits}!OSMO\_BIT\_PRINT\_EX@{OSMO\_BIT\_PRINT\_EX}}
\index{OSMO\_BIT\_PRINT\_EX@{OSMO\_BIT\_PRINT\_EX}!soft, unpacked and packed bits@{soft, unpacked and packed bits}}
\doxysubsubsection{OSMO\_BIT\_PRINT\_EX}
{\footnotesize\ttfamily \#define OSMO\+\_\+\+BIT\+\_\+\+PRINT\+\_\+\+EX(\begin{DoxyParamCaption}\item[{}]{byte,  }\item[{}]{ch }\end{DoxyParamCaption})}

{\bfseries Value\+:}
\begin{DoxyCode}{0}
\DoxyCodeLine{  (\textcolor{keywordtype}{byte} \& 0x80 ? ch : \textcolor{charliteral}{'.'}), \(\backslash\)}
\DoxyCodeLine{  (\textcolor{keywordtype}{byte} \& 0x40 ? ch : \textcolor{charliteral}{'.'}), \(\backslash\)}
\DoxyCodeLine{  (\textcolor{keywordtype}{byte} \& 0x20 ? ch : \textcolor{charliteral}{'.'}), \(\backslash\)}
\DoxyCodeLine{  (\textcolor{keywordtype}{byte} \& 0x10 ? ch : \textcolor{charliteral}{'.'}), \(\backslash\)}
\DoxyCodeLine{  (\textcolor{keywordtype}{byte} \& 0x08 ? ch : \textcolor{charliteral}{'.'}), \(\backslash\)}
\DoxyCodeLine{  (\textcolor{keywordtype}{byte} \& 0x04 ? ch : \textcolor{charliteral}{'.'}), \(\backslash\)}
\DoxyCodeLine{  (\textcolor{keywordtype}{byte} \& 0x02 ? ch : \textcolor{charliteral}{'.'}), \(\backslash\)}
\DoxyCodeLine{  (\textcolor{keywordtype}{byte} \& 0x01 ? ch : \textcolor{charliteral}{'.'})}

\end{DoxyCode}
\mbox{\label{group__bits_ga0edf7ef0d33b16bac63600f37de0478f}} 
\index{soft, unpacked and packed bits@{soft, unpacked and packed bits}!OSMO\_BIT\_SPEC@{OSMO\_BIT\_SPEC}}
\index{OSMO\_BIT\_SPEC@{OSMO\_BIT\_SPEC}!soft, unpacked and packed bits@{soft, unpacked and packed bits}}
\doxysubsubsection{OSMO\_BIT\_SPEC}
{\footnotesize\ttfamily \#define OSMO\+\_\+\+BIT\+\_\+\+SPEC~\char`\"{}\%c\%\textbf{ c}\%\textbf{ c}\%\textbf{ c}\%\textbf{ c}\%\textbf{ c}\%\textbf{ c}\%\textbf{ c}\char`\"{}}



\doxysubsection{Typedef Documentation}
\mbox{\label{group__bits_ga1780d9a13fbdbf69eae79b53092e47db}} 
\index{soft, unpacked and packed bits@{soft, unpacked and packed bits}!pbit\_t@{pbit\_t}}
\index{pbit\_t@{pbit\_t}!soft, unpacked and packed bits@{soft, unpacked and packed bits}}
\doxysubsubsection{pbit\_t}
{\footnotesize\ttfamily typedef uint8\+\_\+t \textbf{ pbit\+\_\+t}}



packed bits (8 bits in a byte). 

NOTE on the endian-\/ness of pbit\+\_\+t\+:
\begin{DoxyItemize}
\item Bits in a \doxyref{pbit\+\_\+t}{p.}{group__bits_ga1780d9a13fbdbf69eae79b53092e47db} are ordered MSB first, i.\+e. 0x80 is the first bit.
\item Bit i in a \doxyref{pbit\+\_\+t}{p.}{group__bits_ga1780d9a13fbdbf69eae79b53092e47db} array is array[i/8] \& (1$<$$<$(7-\/i\%8)) 
\end{DoxyItemize}\mbox{\label{group__bits_gab6b2fe6d30b1abe4a655e9cf033b23ca}} 
\index{soft, unpacked and packed bits@{soft, unpacked and packed bits}!sbit\_t@{sbit\_t}}
\index{sbit\_t@{sbit\_t}!soft, unpacked and packed bits@{soft, unpacked and packed bits}}
\doxysubsubsection{sbit\_t}
{\footnotesize\ttfamily typedef int8\+\_\+t \textbf{ sbit\+\_\+t}}



soft bit with value (-\/127...127), as commonly used in communications receivers such as [viterbi] decoders 

\mbox{\label{group__bits_ga6a432fe43b85ec8e0d13e7de04a3f8ed}} 
\index{soft, unpacked and packed bits@{soft, unpacked and packed bits}!ubit\_t@{ubit\_t}}
\index{ubit\_t@{ubit\_t}!soft, unpacked and packed bits@{soft, unpacked and packed bits}}
\doxysubsubsection{ubit\_t}
{\footnotesize\ttfamily typedef uint8\+\_\+t \textbf{ ubit\+\_\+t}}



unpacked bit (0 or 1)\+: 1 bit per byte 



\doxysubsection{Enumeration Type Documentation}
\mbox{\label{group__bits_ga34685b612429c678efe8c42b2616b12e}} 
\index{soft, unpacked and packed bits@{soft, unpacked and packed bits}!osmo\_br\_mode@{osmo\_br\_mode}}
\index{osmo\_br\_mode@{osmo\_br\_mode}!soft, unpacked and packed bits@{soft, unpacked and packed bits}}
\doxysubsubsection{osmo\_br\_mode}
{\footnotesize\ttfamily enum \textbf{ osmo\+\_\+br\+\_\+mode}}



bit-\/reversal mode for \doxyref{osmo\+\_\+bit\+\_\+reversal()}{p.}{group__bits_gae4f3c9fa5d7ac188213d59dd8f83da40} 

\begin{DoxyEnumFields}{Enumerator}
\raisebox{\heightof{T}}[0pt][0pt]{\index{OSMO\_BR\_BITS\_IN\_DWORD@{OSMO\_BR\_BITS\_IN\_DWORD}!soft, unpacked and packed bits@{soft, unpacked and packed bits}}\index{soft, unpacked and packed bits@{soft, unpacked and packed bits}!OSMO\_BR\_BITS\_IN\_DWORD@{OSMO\_BR\_BITS\_IN\_DWORD}}}\mbox{\label{group__bits_gga34685b612429c678efe8c42b2616b12ea24af110a553e7ac2b7beaa80455d9e78}} 
OSMO\+\_\+\+BR\+\_\+\+BITS\+\_\+\+IN\+\_\+\+DWORD&reverse all bits in a 32bit dword \\
\hline

\raisebox{\heightof{T}}[0pt][0pt]{\index{OSMO\_BR\_BYTES\_IN\_DWORD@{OSMO\_BR\_BYTES\_IN\_DWORD}!soft, unpacked and packed bits@{soft, unpacked and packed bits}}\index{soft, unpacked and packed bits@{soft, unpacked and packed bits}!OSMO\_BR\_BYTES\_IN\_DWORD@{OSMO\_BR\_BYTES\_IN\_DWORD}}}\mbox{\label{group__bits_gga34685b612429c678efe8c42b2616b12ea639e01e0c2eb95e2b1ecdee7f9b1fa77}} 
OSMO\+\_\+\+BR\+\_\+\+BYTES\+\_\+\+IN\+\_\+\+DWORD&reverse byte order in a 32bit dword \\
\hline

\raisebox{\heightof{T}}[0pt][0pt]{\index{OSMO\_BR\_BITS\_IN\_BYTE@{OSMO\_BR\_BITS\_IN\_BYTE}!soft, unpacked and packed bits@{soft, unpacked and packed bits}}\index{soft, unpacked and packed bits@{soft, unpacked and packed bits}!OSMO\_BR\_BITS\_IN\_BYTE@{OSMO\_BR\_BITS\_IN\_BYTE}}}\mbox{\label{group__bits_gga34685b612429c678efe8c42b2616b12eadd4dada5dd7984bac5929d303cbb3ea3}} 
OSMO\+\_\+\+BR\+\_\+\+BITS\+\_\+\+IN\+\_\+\+BYTE&reverse bits of each byte in a 32bit dword \\
\hline

\raisebox{\heightof{T}}[0pt][0pt]{\index{OSMO\_BR\_WORD\_SWAP@{OSMO\_BR\_WORD\_SWAP}!soft, unpacked and packed bits@{soft, unpacked and packed bits}}\index{soft, unpacked and packed bits@{soft, unpacked and packed bits}!OSMO\_BR\_WORD\_SWAP@{OSMO\_BR\_WORD\_SWAP}}}\mbox{\label{group__bits_gga34685b612429c678efe8c42b2616b12eaed9c48da86bcc42f6fd6c33ca458287d}} 
OSMO\+\_\+\+BR\+\_\+\+WORD\+\_\+\+SWAP&swap the two 16bit words in a 32bit dword \\
\hline

\end{DoxyEnumFields}


\doxysubsection{Function Documentation}
\mbox{\label{group__bits_gae4f3c9fa5d7ac188213d59dd8f83da40}} 
\index{soft, unpacked and packed bits@{soft, unpacked and packed bits}!osmo\_bit\_reversal@{osmo\_bit\_reversal}}
\index{osmo\_bit\_reversal@{osmo\_bit\_reversal}!soft, unpacked and packed bits@{soft, unpacked and packed bits}}
\doxysubsubsection{osmo\_bit\_reversal()}
{\footnotesize\ttfamily uint32\+\_\+t osmo\+\_\+bit\+\_\+reversal (\begin{DoxyParamCaption}\item[{uint32\+\_\+t}]{x,  }\item[{enum \textbf{ osmo\+\_\+br\+\_\+mode}}]{k }\end{DoxyParamCaption})}



generalized bit reversal function 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em x} & the 32bit value to be reversed \\
\hline
\mbox{\texttt{ in}}  & {\em k} & the type of reversal requested \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
the reversed 32bit dword
\end{DoxyReturn}
This function reverses the bit order within a 32bit word. Depending on \char`\"{}k\char`\"{}, it either reverses all bits in a 32bit dword, or the bytes in the dword, or the bits in each byte of a dword, or simply swaps the two 16bit words in a dword. See Chapter 7 \char`\"{}\+Hackers Delight\char`\"{} 

References \textbf{ k}, and \textbf{ x}.

\mbox{\label{group__bits_ga720f02d3e0b8ead8892ea2796551d5cf}} 
\index{soft, unpacked and packed bits@{soft, unpacked and packed bits}!osmo\_nibble\_shift\_left\_unal@{osmo\_nibble\_shift\_left\_unal}}
\index{osmo\_nibble\_shift\_left\_unal@{osmo\_nibble\_shift\_left\_unal}!soft, unpacked and packed bits@{soft, unpacked and packed bits}}
\doxysubsubsection{osmo\_nibble\_shift\_left\_unal()}
{\footnotesize\ttfamily void osmo\+\_\+nibble\+\_\+shift\+\_\+left\+\_\+unal (\begin{DoxyParamCaption}\item[{uint8\+\_\+t $\ast$}]{out,  }\item[{const uint8\+\_\+t $\ast$}]{in,  }\item[{unsigned int}]{num\+\_\+nibbles }\end{DoxyParamCaption})}



Shift unaligned input to octet-\/aligned output. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ out}}  & {\em out} & output buffer, octet-\/aligned \\
\hline
\mbox{\texttt{ in}}  & {\em in} & input buffer, unaligned \\
\hline
\mbox{\texttt{ in}}  & {\em num\+\_\+nibbles} & number of nibbles \\
\hline
\end{DoxyParams}
\mbox{\label{group__bits_gacc781ff2ed10005457258a5f435c96fb}} 
\index{soft, unpacked and packed bits@{soft, unpacked and packed bits}!osmo\_nibble\_shift\_right@{osmo\_nibble\_shift\_right}}
\index{osmo\_nibble\_shift\_right@{osmo\_nibble\_shift\_right}!soft, unpacked and packed bits@{soft, unpacked and packed bits}}
\doxysubsubsection{osmo\_nibble\_shift\_right()}
{\footnotesize\ttfamily void osmo\+\_\+nibble\+\_\+shift\+\_\+right (\begin{DoxyParamCaption}\item[{uint8\+\_\+t $\ast$}]{out,  }\item[{const uint8\+\_\+t $\ast$}]{in,  }\item[{unsigned int}]{num\+\_\+nibbles }\end{DoxyParamCaption})}



Shift unaligned input to octet-\/aligned output. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ out}}  & {\em out} & output buffer, unaligned \\
\hline
\mbox{\texttt{ in}}  & {\em in} & input buffer, octet-\/aligned \\
\hline
\mbox{\texttt{ in}}  & {\em num\+\_\+nibbles} & number of nibbles \\
\hline
\end{DoxyParams}
\mbox{\label{group__bits_ga6061c0bccf3149afbfd3717655926610}} 
\index{soft, unpacked and packed bits@{soft, unpacked and packed bits}!osmo\_pbit2ubit@{osmo\_pbit2ubit}}
\index{osmo\_pbit2ubit@{osmo\_pbit2ubit}!soft, unpacked and packed bits@{soft, unpacked and packed bits}}
\doxysubsubsection{osmo\_pbit2ubit()}
{\footnotesize\ttfamily int osmo\+\_\+pbit2ubit (\begin{DoxyParamCaption}\item[{\textbf{ ubit\+\_\+t} $\ast$}]{out,  }\item[{const \textbf{ pbit\+\_\+t} $\ast$}]{in,  }\item[{unsigned int}]{num\+\_\+bits }\end{DoxyParamCaption})}



convert packed bits to unpacked bits, return length in bytes 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ out}}  & {\em out} & output buffer of unpacked bits \\
\hline
\mbox{\texttt{ in}}  & {\em in} & input buffer of packed bits \\
\hline
\mbox{\texttt{ in}}  & {\em num\+\_\+bits} & number of bits \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
number of bytes used in out 
\end{DoxyReturn}
\mbox{\label{group__bits_ga7978cf8714618d6682751058818444c6}} 
\index{soft, unpacked and packed bits@{soft, unpacked and packed bits}!osmo\_pbit2ubit\_ext@{osmo\_pbit2ubit\_ext}}
\index{osmo\_pbit2ubit\_ext@{osmo\_pbit2ubit\_ext}!soft, unpacked and packed bits@{soft, unpacked and packed bits}}
\doxysubsubsection{osmo\_pbit2ubit\_ext()}
{\footnotesize\ttfamily int osmo\+\_\+pbit2ubit\+\_\+ext (\begin{DoxyParamCaption}\item[{\textbf{ ubit\+\_\+t} $\ast$}]{out,  }\item[{unsigned int}]{out\+\_\+ofs,  }\item[{const \textbf{ pbit\+\_\+t} $\ast$}]{in,  }\item[{unsigned int}]{in\+\_\+ofs,  }\item[{unsigned int}]{num\+\_\+bits,  }\item[{int}]{lsb\+\_\+mode }\end{DoxyParamCaption})}



convert packed bits to unpacked bits (extended options) 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ out}}  & {\em out} & output buffer of unpacked bits \\
\hline
\mbox{\texttt{ in}}  & {\em out\+\_\+ofs} & offset into output buffer \\
\hline
\mbox{\texttt{ in}}  & {\em in} & input buffer of packed bits \\
\hline
\mbox{\texttt{ in}}  & {\em in\+\_\+ofs} & offset into input buffer \\
\hline
\mbox{\texttt{ in}}  & {\em num\+\_\+bits} & number of bits \\
\hline
\mbox{\texttt{ in}}  & {\em lsb\+\_\+mode} & Encode bits in LSB order instead of MSB \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
length in bytes (max written offset of output buffer + 1) 
\end{DoxyReturn}
\mbox{\label{group__bits_ga2d7ddc29e908961ad898356a720ddd45}} 
\index{soft, unpacked and packed bits@{soft, unpacked and packed bits}!osmo\_pbit\_bytesize@{osmo\_pbit\_bytesize}}
\index{osmo\_pbit\_bytesize@{osmo\_pbit\_bytesize}!soft, unpacked and packed bits@{soft, unpacked and packed bits}}
\doxysubsubsection{osmo\_pbit\_bytesize()}
{\footnotesize\ttfamily static unsigned int osmo\+\_\+pbit\+\_\+bytesize (\begin{DoxyParamCaption}\item[{unsigned int}]{num\+\_\+bits }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}, {\ttfamily [static]}}



determine how many bytes we would need for {\itshape num\+\_\+bits} packed bits 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em num\+\_\+bits} & Number of packed bits \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
number of bytes needed for {\itshape num\+\_\+bits} packed bits 
\end{DoxyReturn}
\mbox{\label{group__bits_ga7c83c316140d1209f4b2dc83b3eea5cf}} 
\index{soft, unpacked and packed bits@{soft, unpacked and packed bits}!osmo\_revbytebits\_32@{osmo\_revbytebits\_32}}
\index{osmo\_revbytebits\_32@{osmo\_revbytebits\_32}!soft, unpacked and packed bits@{soft, unpacked and packed bits}}
\doxysubsubsection{osmo\_revbytebits\_32()}
{\footnotesize\ttfamily uint32\+\_\+t osmo\+\_\+revbytebits\+\_\+32 (\begin{DoxyParamCaption}\item[{uint32\+\_\+t}]{x }\end{DoxyParamCaption})}



reverse the bit-\/order in each byte of a dword 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em x} & 32bit input value \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
32bit value where bits of each byte have been reversed
\end{DoxyReturn}
See Chapter 7 \char`\"{}\+Hackers Delight\char`\"{} 

References \textbf{ x}.

\mbox{\label{group__bits_gafe16634bf4f34bd4dd0f7bc5dcf54e33}} 
\index{soft, unpacked and packed bits@{soft, unpacked and packed bits}!osmo\_revbytebits\_8@{osmo\_revbytebits\_8}}
\index{osmo\_revbytebits\_8@{osmo\_revbytebits\_8}!soft, unpacked and packed bits@{soft, unpacked and packed bits}}
\doxysubsubsection{osmo\_revbytebits\_8()}
{\footnotesize\ttfamily uint32\+\_\+t osmo\+\_\+revbytebits\+\_\+8 (\begin{DoxyParamCaption}\item[{uint8\+\_\+t}]{x }\end{DoxyParamCaption})}



reverse the bit order in a byte 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em x} & 8bit input value \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
8bit value where bits order has been reversed 
\end{DoxyReturn}


References \textbf{ flip\+\_\+table}, and \textbf{ x}.



Referenced by \textbf{ osmo\+\_\+isdnhdlc\+\_\+decode()}, and \textbf{ osmo\+\_\+isdnhdlc\+\_\+encode()}.

\mbox{\label{group__bits_gab44abd4982a164c8e2e5588d9fd81852}} 
\index{soft, unpacked and packed bits@{soft, unpacked and packed bits}!osmo\_revbytebits\_buf@{osmo\_revbytebits\_buf}}
\index{osmo\_revbytebits\_buf@{osmo\_revbytebits\_buf}!soft, unpacked and packed bits@{soft, unpacked and packed bits}}
\doxysubsubsection{osmo\_revbytebits\_buf()}
{\footnotesize\ttfamily void osmo\+\_\+revbytebits\+\_\+buf (\begin{DoxyParamCaption}\item[{uint8\+\_\+t $\ast$}]{buf,  }\item[{int}]{len }\end{DoxyParamCaption})}



reverse bit-\/order of each byte in a buffer 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em buf} & buffer containing bytes to be bit-\/reversed \\
\hline
\mbox{\texttt{ in}}  & {\em len} & length of buffer in bytes\\
\hline
\end{DoxyParams}
This function reverses the bits in each byte of the buffer 

References \textbf{ flip\+\_\+table}, and \textbf{ len()}.

\mbox{\label{group__bits_gac3e432aa41d4435a5d206da5b7f9a7e6}} 
\index{soft, unpacked and packed bits@{soft, unpacked and packed bits}!osmo\_rol16@{osmo\_rol16}}
\index{osmo\_rol16@{osmo\_rol16}!soft, unpacked and packed bits@{soft, unpacked and packed bits}}
\doxysubsubsection{osmo\_rol16()}
{\footnotesize\ttfamily static uint16\+\_\+t osmo\+\_\+rol16 (\begin{DoxyParamCaption}\item[{uint16\+\_\+t}]{in,  }\item[{unsigned}]{shift }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}, {\ttfamily [static]}}



left circular shift 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em in} & The 16 bit unsigned integer to be rotated \\
\hline
\mbox{\texttt{ in}}  & {\em shift} & Number of bits to shift {\itshape in} to, [0;16] bits \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
shifted value 
\end{DoxyReturn}
\mbox{\label{group__bits_ga520d72b80bd83e41b58afe012005984f}} 
\index{soft, unpacked and packed bits@{soft, unpacked and packed bits}!osmo\_sbit2ubit@{osmo\_sbit2ubit}}
\index{osmo\_sbit2ubit@{osmo\_sbit2ubit}!soft, unpacked and packed bits@{soft, unpacked and packed bits}}
\doxysubsubsection{osmo\_sbit2ubit()}
{\footnotesize\ttfamily void osmo\+\_\+sbit2ubit (\begin{DoxyParamCaption}\item[{\textbf{ ubit\+\_\+t} $\ast$}]{out,  }\item[{const \textbf{ sbit\+\_\+t} $\ast$}]{in,  }\item[{unsigned int}]{num\+\_\+bits }\end{DoxyParamCaption})}



convert soft bits to unpacked bits 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ out}}  & {\em out} & output buffer of unpacked bits \\
\hline
\mbox{\texttt{ in}}  & {\em in} & input buffer of soft bits \\
\hline
\mbox{\texttt{ in}}  & {\em num\+\_\+bits} & number of bits \\
\hline
\end{DoxyParams}
\mbox{\label{group__bits_ga0396755b3f1fb67dda62c6310bcefae5}} 
\index{soft, unpacked and packed bits@{soft, unpacked and packed bits}!osmo\_ubit2pbit@{osmo\_ubit2pbit}}
\index{osmo\_ubit2pbit@{osmo\_ubit2pbit}!soft, unpacked and packed bits@{soft, unpacked and packed bits}}
\doxysubsubsection{osmo\_ubit2pbit()}
{\footnotesize\ttfamily int osmo\+\_\+ubit2pbit (\begin{DoxyParamCaption}\item[{\textbf{ pbit\+\_\+t} $\ast$}]{out,  }\item[{const \textbf{ ubit\+\_\+t} $\ast$}]{in,  }\item[{unsigned int}]{num\+\_\+bits }\end{DoxyParamCaption})}



convert unpacked bits to packed bits, return length in bytes 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ out}}  & {\em out} & output buffer of packed bits \\
\hline
\mbox{\texttt{ in}}  & {\em in} & input buffer of unpacked bits \\
\hline
\mbox{\texttt{ in}}  & {\em num\+\_\+bits} & number of bits \\
\hline
\end{DoxyParams}
\mbox{\label{group__bits_ga55b990334c0b0188134d42b6a201d6bc}} 
\index{soft, unpacked and packed bits@{soft, unpacked and packed bits}!osmo\_ubit2pbit\_ext@{osmo\_ubit2pbit\_ext}}
\index{osmo\_ubit2pbit\_ext@{osmo\_ubit2pbit\_ext}!soft, unpacked and packed bits@{soft, unpacked and packed bits}}
\doxysubsubsection{osmo\_ubit2pbit\_ext()}
{\footnotesize\ttfamily int osmo\+\_\+ubit2pbit\+\_\+ext (\begin{DoxyParamCaption}\item[{\textbf{ pbit\+\_\+t} $\ast$}]{out,  }\item[{unsigned int}]{out\+\_\+ofs,  }\item[{const \textbf{ ubit\+\_\+t} $\ast$}]{in,  }\item[{unsigned int}]{in\+\_\+ofs,  }\item[{unsigned int}]{num\+\_\+bits,  }\item[{int}]{lsb\+\_\+mode }\end{DoxyParamCaption})}



convert unpacked bits to packed bits (extended options) 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ out}}  & {\em out} & output buffer of packed bits \\
\hline
\mbox{\texttt{ in}}  & {\em out\+\_\+ofs} & offset into output buffer \\
\hline
\mbox{\texttt{ in}}  & {\em in} & input buffer of unpacked bits \\
\hline
\mbox{\texttt{ in}}  & {\em in\+\_\+ofs} & offset into input buffer \\
\hline
\mbox{\texttt{ in}}  & {\em num\+\_\+bits} & number of bits \\
\hline
\mbox{\texttt{ in}}  & {\em lsb\+\_\+mode} & Encode bits in LSB order instead of MSB \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
length in bytes (max written offset of output buffer + 1) 
\end{DoxyReturn}
\mbox{\label{group__bits_ga9a76a29b0916e9cd26c5ca65dbbfb325}} 
\index{soft, unpacked and packed bits@{soft, unpacked and packed bits}!osmo\_ubit2sbit@{osmo\_ubit2sbit}}
\index{osmo\_ubit2sbit@{osmo\_ubit2sbit}!soft, unpacked and packed bits@{soft, unpacked and packed bits}}
\doxysubsubsection{osmo\_ubit2sbit()}
{\footnotesize\ttfamily void osmo\+\_\+ubit2sbit (\begin{DoxyParamCaption}\item[{\textbf{ sbit\+\_\+t} $\ast$}]{out,  }\item[{const \textbf{ ubit\+\_\+t} $\ast$}]{in,  }\item[{unsigned int}]{num\+\_\+bits }\end{DoxyParamCaption})}



convert unpacked bits to soft bits 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ out}}  & {\em out} & output buffer of soft bits \\
\hline
\mbox{\texttt{ in}}  & {\em in} & input buffer of unpacked bits \\
\hline
\mbox{\texttt{ in}}  & {\em num\+\_\+bits} & number of bits \\
\hline
\end{DoxyParams}


\doxysubsection{Variable Documentation}
\mbox{\label{group__bits_ga7cc2859ee2b88036f7229b3e5102dfbe}} 
\index{soft, unpacked and packed bits@{soft, unpacked and packed bits}!flip\_table@{flip\_table}}
\index{flip\_table@{flip\_table}!soft, unpacked and packed bits@{soft, unpacked and packed bits}}
\doxysubsubsection{flip\_table}
{\footnotesize\ttfamily const uint8\+\_\+t flip\+\_\+table[256]\hspace{0.3cm}{\ttfamily [static]}}

{\bfseries Initial value\+:}
\begin{DoxyCode}{0}
\DoxyCodeLine{= \{}
\DoxyCodeLine{        0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,}
\DoxyCodeLine{        0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8, 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,}
\DoxyCodeLine{        0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4, 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,}
\DoxyCodeLine{        0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec, 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,}
\DoxyCodeLine{        0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2, 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,}
\DoxyCodeLine{        0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea, 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,}
\DoxyCodeLine{        0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6, 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,}
\DoxyCodeLine{        0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee, 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,}
\DoxyCodeLine{        0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1, 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,}
\DoxyCodeLine{        0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9, 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,}
\DoxyCodeLine{        0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5, 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,}
\DoxyCodeLine{        0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed, 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,}
\DoxyCodeLine{        0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3, 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,}
\DoxyCodeLine{        0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb, 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,}
\DoxyCodeLine{        0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7, 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,}
\DoxyCodeLine{        0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff,}
\DoxyCodeLine{\}}

\end{DoxyCode}


Referenced by \textbf{ osmo\+\_\+revbytebits\+\_\+8()}, and \textbf{ osmo\+\_\+revbytebits\+\_\+buf()}.

