\doxysection{byteswap.\+h}
\label{byteswap_8h_source}\index{include/osmocom/core/byteswap.h@{include/osmocom/core/byteswap.h}}
\textbf{ Go to the documentation of this file.}
\begin{DoxyCode}{0}
\DoxyCodeLine{1 }
\DoxyCodeLine{3 \textcolor{preprocessor}{\#pragma once}}
\DoxyCodeLine{4 \textcolor{preprocessor}{\#include <stdint.h>}}
\DoxyCodeLine{5 \textcolor{preprocessor}{\#include <osmocom/core/endian.h>}}
\DoxyCodeLine{6 }
\DoxyCodeLine{10 \textcolor{keyword}{static} \textcolor{keyword}{inline} uint32\_t osmo\_swab32(uint32\_t in)}
\DoxyCodeLine{11 \{}
\DoxyCodeLine{12         uint32\_t out;}
\DoxyCodeLine{13 }
\DoxyCodeLine{14         out = (in \& 0xff) << 24;}
\DoxyCodeLine{15         out |= (in \& 0xff00) << 8;}
\DoxyCodeLine{16         out |= (in \& 0xff0000) >> 8;}
\DoxyCodeLine{17         out |= (in \& 0xff000000) >> 24;}
\DoxyCodeLine{18 }
\DoxyCodeLine{19         \textcolor{keywordflow}{return} out;}
\DoxyCodeLine{20 \}}
\DoxyCodeLine{21 }
\DoxyCodeLine{25 \textcolor{keyword}{static} \textcolor{keyword}{inline} uint16\_t osmo\_swab16(uint16\_t in)}
\DoxyCodeLine{26 \{}
\DoxyCodeLine{27         uint16\_t out;}
\DoxyCodeLine{28 }
\DoxyCodeLine{29         out = (in \& 0xff) << 8;}
\DoxyCodeLine{30         out |= (in \& 0xff00) >> 8;}
\DoxyCodeLine{31 }
\DoxyCodeLine{32         \textcolor{keywordflow}{return} out;}
\DoxyCodeLine{33 \}}
\DoxyCodeLine{34 }
\DoxyCodeLine{35 \textcolor{preprocessor}{\#if OSMO\_IS\_LITTLE\_ENDIAN == 1}}
\DoxyCodeLine{36 \textcolor{preprocessor}{\#define osmo\_ntohl(x)   osmo\_swab32(x)}}
\DoxyCodeLine{37 \textcolor{preprocessor}{\#define osmo\_ntohs(x)   osmo\_swab16(x)}}
\DoxyCodeLine{38 \textcolor{preprocessor}{\#define osmo\_htonl(x)   osmo\_swab32(x)}}
\DoxyCodeLine{39 \textcolor{preprocessor}{\#define osmo\_htons(x)   osmo\_swab16(x)}}
\DoxyCodeLine{40 \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{41 \textcolor{preprocessor}{\#define osmo\_ntohl(x)   (x)}}
\DoxyCodeLine{42 \textcolor{preprocessor}{\#define osmo\_ntohs(x)   (x)}}
\DoxyCodeLine{43 \textcolor{preprocessor}{\#define osmo\_htonl(x)   (x)}}
\DoxyCodeLine{44 \textcolor{preprocessor}{\#define osmo\_htons(x)   (x)}}
\DoxyCodeLine{45 \textcolor{preprocessor}{\#endif}}

\end{DoxyCode}
