\doxysection{bits.\+h}
\label{bits_8h_source}\index{include/osmocom/core/bits.h@{include/osmocom/core/bits.h}}
\textbf{ Go to the documentation of this file.}
\begin{DoxyCode}{0}
\DoxyCodeLine{1 }
\DoxyCodeLine{6 \textcolor{preprocessor}{\#pragma once}}
\DoxyCodeLine{7 }
\DoxyCodeLine{8 \textcolor{preprocessor}{\#include <stdint.h>}}
\DoxyCodeLine{9 \textcolor{preprocessor}{\#include <stddef.h>}}
\DoxyCodeLine{10 }
\DoxyCodeLine{11 \textcolor{preprocessor}{\#include <osmocom/core/bit16gen.h>}}
\DoxyCodeLine{12 \textcolor{preprocessor}{\#include <osmocom/core/bit32gen.h>}}
\DoxyCodeLine{13 \textcolor{preprocessor}{\#include <osmocom/core/bit64gen.h>}}
\DoxyCodeLine{14 }
\DoxyCodeLine{21 \textcolor{keyword}{typedef} int8\_t  sbit\_t;}
\DoxyCodeLine{22 }
\DoxyCodeLine{24 \textcolor{keyword}{typedef} uint8\_t ubit\_t;}
\DoxyCodeLine{25 }
\DoxyCodeLine{30 \textcolor{keyword}{typedef} uint8\_t pbit\_t;}
\DoxyCodeLine{31 }
\DoxyCodeLine{36 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} osmo\_pbit\_bytesize(\textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} num\_bits)}
\DoxyCodeLine{37 \{}
\DoxyCodeLine{38         \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} pbit\_bytesize = num\_bits / 8;}
\DoxyCodeLine{39 }
\DoxyCodeLine{40         \textcolor{keywordflow}{if} (num\_bits \% 8)}
\DoxyCodeLine{41                 pbit\_bytesize++;}
\DoxyCodeLine{42 }
\DoxyCodeLine{43         \textcolor{keywordflow}{return} pbit\_bytesize;}
\DoxyCodeLine{44 \}}
\DoxyCodeLine{45 }
\DoxyCodeLine{46 \textcolor{keywordtype}{int} osmo\_ubit2pbit(pbit\_t *out, \textcolor{keyword}{const} ubit\_t *in, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} num\_bits);}
\DoxyCodeLine{47 }
\DoxyCodeLine{48 \textcolor{keywordtype}{int} osmo\_pbit2ubit(ubit\_t *out, \textcolor{keyword}{const} pbit\_t *in, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} num\_bits);}
\DoxyCodeLine{49 }
\DoxyCodeLine{50 \textcolor{keywordtype}{void} osmo\_nibble\_shift\_right(uint8\_t *out, \textcolor{keyword}{const} uint8\_t *in,}
\DoxyCodeLine{51                              \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} num\_nibbles);}
\DoxyCodeLine{52 \textcolor{keywordtype}{void} osmo\_nibble\_shift\_left\_unal(uint8\_t *out, \textcolor{keyword}{const} uint8\_t *in,}
\DoxyCodeLine{53                                  \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} num\_nibbles);}
\DoxyCodeLine{54 }
\DoxyCodeLine{55 \textcolor{keywordtype}{void} osmo\_ubit2sbit(sbit\_t *out, \textcolor{keyword}{const} ubit\_t *in, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} num\_bits);}
\DoxyCodeLine{56 \textcolor{keywordtype}{void} osmo\_sbit2ubit(ubit\_t *out, \textcolor{keyword}{const} sbit\_t *in, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} num\_bits);}
\DoxyCodeLine{57 }
\DoxyCodeLine{58 \textcolor{keywordtype}{int} osmo\_ubit2pbit\_ext(pbit\_t *out, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} out\_ofs,}
\DoxyCodeLine{59                        \textcolor{keyword}{const} ubit\_t *in, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} in\_ofs,}
\DoxyCodeLine{60                        \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} num\_bits, \textcolor{keywordtype}{int} lsb\_mode);}
\DoxyCodeLine{61 }
\DoxyCodeLine{62 \textcolor{keywordtype}{int} osmo\_pbit2ubit\_ext(ubit\_t *out, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} out\_ofs,}
\DoxyCodeLine{63                        \textcolor{keyword}{const} pbit\_t *in, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} in\_ofs,}
\DoxyCodeLine{64                        \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} num\_bits, \textcolor{keywordtype}{int} lsb\_mode);}
\DoxyCodeLine{65 }
\DoxyCodeLine{66 \textcolor{preprocessor}{\#define OSMO\_BIN\_SPEC "{}\%d\%d\%d\%d\%d\%d\%d\%d"{}}}
\DoxyCodeLine{67 \textcolor{preprocessor}{\#define OSMO\_BIN\_PRINT(byte)  \(\backslash\)}}
\DoxyCodeLine{68 \textcolor{preprocessor}{  (byte \& 0x80 ? 1 : 0), \(\backslash\)}}
\DoxyCodeLine{69 \textcolor{preprocessor}{  (byte \& 0x40 ? 1 : 0), \(\backslash\)}}
\DoxyCodeLine{70 \textcolor{preprocessor}{  (byte \& 0x20 ? 1 : 0), \(\backslash\)}}
\DoxyCodeLine{71 \textcolor{preprocessor}{  (byte \& 0x10 ? 1 : 0), \(\backslash\)}}
\DoxyCodeLine{72 \textcolor{preprocessor}{  (byte \& 0x08 ? 1 : 0), \(\backslash\)}}
\DoxyCodeLine{73 \textcolor{preprocessor}{  (byte \& 0x04 ? 1 : 0), \(\backslash\)}}
\DoxyCodeLine{74 \textcolor{preprocessor}{  (byte \& 0x02 ? 1 : 0), \(\backslash\)}}
\DoxyCodeLine{75 \textcolor{preprocessor}{  (byte \& 0x01 ? 1 : 0)}}
\DoxyCodeLine{76 }
\DoxyCodeLine{77 \textcolor{preprocessor}{\#define OSMO\_BIT\_SPEC "{}\%c\%c\%c\%c\%c\%c\%c\%c"{}}}
\DoxyCodeLine{78 \textcolor{preprocessor}{\#define OSMO\_BIT\_PRINT\_EX(byte, ch)             \(\backslash\)}}
\DoxyCodeLine{79 \textcolor{preprocessor}{  (byte \& 0x80 ? ch : '.'), \(\backslash\)}}
\DoxyCodeLine{80 \textcolor{preprocessor}{  (byte \& 0x40 ? ch : '.'), \(\backslash\)}}
\DoxyCodeLine{81 \textcolor{preprocessor}{  (byte \& 0x20 ? ch : '.'), \(\backslash\)}}
\DoxyCodeLine{82 \textcolor{preprocessor}{  (byte \& 0x10 ? ch : '.'), \(\backslash\)}}
\DoxyCodeLine{83 \textcolor{preprocessor}{  (byte \& 0x08 ? ch : '.'), \(\backslash\)}}
\DoxyCodeLine{84 \textcolor{preprocessor}{  (byte \& 0x04 ? ch : '.'), \(\backslash\)}}
\DoxyCodeLine{85 \textcolor{preprocessor}{  (byte \& 0x02 ? ch : '.'), \(\backslash\)}}
\DoxyCodeLine{86 \textcolor{preprocessor}{  (byte \& 0x01 ? ch : '.')}}
\DoxyCodeLine{87 }
\DoxyCodeLine{88 \textcolor{preprocessor}{\#define OSMO\_BIT\_PRINT(byte)  OSMO\_BIT\_PRINT\_EX(byte, '1')}}
\DoxyCodeLine{89 }
\DoxyCodeLine{90 \textcolor{comment}{/* BIT REVERSAL */}}
\DoxyCodeLine{91 }
\DoxyCodeLine{93 \textcolor{keyword}{enum} osmo\_br\_mode \{}
\DoxyCodeLine{95         OSMO\_BR\_BITS\_IN\_DWORD      = 31,}
\DoxyCodeLine{97         OSMO\_BR\_BYTES\_IN\_DWORD    = 24,}
\DoxyCodeLine{99         OSMO\_BR\_BITS\_IN\_BYTE        = 7,}
\DoxyCodeLine{101         OSMO\_BR\_WORD\_SWAP      = 16,}
\DoxyCodeLine{102 \};}
\DoxyCodeLine{103 }
\DoxyCodeLine{104 uint32\_t osmo\_bit\_reversal(uint32\_t x, \textcolor{keyword}{enum} osmo\_br\_mode k);}
\DoxyCodeLine{105 }
\DoxyCodeLine{106 uint32\_t osmo\_revbytebits\_32(uint32\_t x);}
\DoxyCodeLine{107 }
\DoxyCodeLine{108 uint32\_t osmo\_revbytebits\_8(uint8\_t x);}
\DoxyCodeLine{109 }
\DoxyCodeLine{110 \textcolor{keywordtype}{void} osmo\_revbytebits\_buf(uint8\_t *buf, \textcolor{keywordtype}{int} len);}
\DoxyCodeLine{111 }
\DoxyCodeLine{117 \textcolor{keyword}{static} \textcolor{keyword}{inline} uint16\_t osmo\_rol16(uint16\_t in, \textcolor{keywordtype}{unsigned} shift)}
\DoxyCodeLine{118 \{}
\DoxyCodeLine{119         \textcolor{keywordflow}{return} (in << shift) | (in >> (16 -\/ shift));}
\DoxyCodeLine{120 \}}
\DoxyCodeLine{121 }

\end{DoxyCode}
