man-pages/man3/bswap.3.html
2021-03-31 01:06:50 +01:00

126 lines
3.6 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of BSWAP</TITLE>
</HEAD><BODY>
<H1>BSWAP</H1>
Section: Linux Programmer's Manual (3)<BR>Updated: 2019-03-06<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
bswap_16, bswap_32, bswap_64 - reverse order of bytes
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
<B>#include &lt;<A HREF="file:///usr/include/byteswap.h">byteswap.h</A>&gt;</B>
<B>bswap_16(</B><I>x</I><B>);</B>
<B>bswap_32(</B><I>x</I><B>);</B>
<B>bswap_64(</B><I>x</I><B>);</B>
</PRE>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
These macros return a value in which the order of the bytes
in their 2-, 4-, or 8-byte arguments is reversed.
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
These macros return the value of their argument with the bytes reversed.
<A NAME="lbAF">&nbsp;</A>
<H2>ERRORS</H2>
These macros always succeed.
<A NAME="lbAG">&nbsp;</A>
<H2>CONFORMING TO</H2>
These macros are GNU extensions.
<A NAME="lbAH">&nbsp;</A>
<H2>EXAMPLE</H2>
The program below swaps the bytes of the 8-byte integer supplied as
its command-line argument.
The following shell session demonstrates the use of the program:
<P>
$ <B>./a.out 0x0123456789abcdef</B>
0x123456789abcdef ==&gt; 0xefcdab8967452301
<A NAME="lbAI">&nbsp;</A>
<H3>Program source</H3>
#include &lt;<A HREF="file:///usr/include/stdio.h">stdio.h</A>&gt;
#include &lt;<A HREF="file:///usr/include/stdint.h">stdint.h</A>&gt;
#include &lt;<A HREF="file:///usr/include/stdlib.h">stdlib.h</A>&gt;
#include &lt;<A HREF="file:///usr/include/inttypes.h">inttypes.h</A>&gt;
#include &lt;<A HREF="file:///usr/include/byteswap.h">byteswap.h</A>&gt;
<P>
int
main(int argc, char *argv[])
{
<BR>&nbsp;&nbsp;&nbsp;&nbsp;uint64_t&nbsp;x;
<P>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(argc&nbsp;!=&nbsp;2)&nbsp;{
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fprintf(stderr,&nbsp;&quot;Usage:&nbsp;%s&nbsp;&lt;num&gt;\n&quot;,&nbsp;argv[0]);
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit(EXIT_FAILURE);
<BR>&nbsp;&nbsp;&nbsp;&nbsp;}
<P>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;x&nbsp;=&nbsp;strtoul(argv[1],&nbsp;NULL,&nbsp;0);
<BR>&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;0x%&quot;&nbsp;PRIx64&nbsp;&quot;&nbsp;==&gt;&nbsp;0x%&quot;&nbsp;PRIx64&nbsp;&quot;\n&quot;,&nbsp;x,&nbsp;bswap_64(x));
<P>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;exit(EXIT_SUCCESS);
}
<A NAME="lbAJ">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?3+byteorder">byteorder</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+endian">endian</A></B>(3)
<A NAME="lbAK">&nbsp;</A>
<H2>COLOPHON</H2>
This page is part of release 5.05 of the Linux
<I>man-pages</I>
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="1"><A HREF="#lbAB">NAME</A><DD>
<DT id="2"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="3"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="4"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT id="5"><A HREF="#lbAF">ERRORS</A><DD>
<DT id="6"><A HREF="#lbAG">CONFORMING TO</A><DD>
<DT id="7"><A HREF="#lbAH">EXAMPLE</A><DD>
<DL>
<DT id="8"><A HREF="#lbAI">Program source</A><DD>
</DL>
<DT id="9"><A HREF="#lbAJ">SEE ALSO</A><DD>
<DT id="10"><A HREF="#lbAK">COLOPHON</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:36 GMT, March 31, 2021
</BODY>
</HTML>