<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <!--Converted with LaTeX2HTML 2008 (1.71) original version by: Nikos Drakos, CBLU, University of Leeds * revised and updated by: Marcus Hennecke, Ross Moore, Herb Swan * with significant contributions from: Jens Lippmann, Marek Rouchal, Martin Wilck and others --> <HTML> <HEAD> <TITLE>8.1.10 Nibble and Byte Swapping</TITLE> <META NAME="description" CONTENT="8.1.10 Nibble and Byte Swapping"> <META NAME="keywords" CONTENT="sdccman"> <META NAME="resource-type" CONTENT="document"> <META NAME="distribution" CONTENT="global"> <META NAME="Generator" CONTENT="LaTeX2HTML v2008"> <META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css"> <LINK REL="STYLESHEET" HREF="sdccman.css"> <LINK REL="next" HREF="node180.html"> <LINK REL="previous" HREF="node178.html"> <LINK REL="up" HREF="node169.html"> <LINK REL="next" HREF="node180.html"> </HEAD> <BODY > <!--Navigation Panel--> <A NAME="tex2html3497" HREF="node180.html"> <IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A> <A NAME="tex2html3491" HREF="node169.html"> <IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A> <A NAME="tex2html3485" HREF="node178.html"> <IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A> <A NAME="tex2html3493" HREF="node1.html"> <IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.png"></A> <A NAME="tex2html3495" HREF="node191.html"> <IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index.png"></A> <BR> <B> Next:</B> <A NAME="tex2html3498" HREF="node180.html">8.1.11 Highest Order Bit</A> <B> Up:</B> <A NAME="tex2html3492" HREF="node169.html">8.1 Optimizations</A> <B> Previous:</B> <A NAME="tex2html3486" HREF="node178.html">8.1.9 Bit-rotation</A> <B> <A NAME="tex2html3494" HREF="node1.html">Contents</A></B> <B> <A NAME="tex2html3496" HREF="node191.html">Index</A></B> <BR> <BR> <!--End of Navigation Panel--> <H2><A NAME="SECTION009110000000000000000"> 8.1.10 Nibble and Byte Swapping</A> </H2> <P> Other special cases of the bit-shift operations are nibble or byte swapping<A NAME="4207"></A>, SDCC recognizes the following expressions: <BLOCKQUOTE> <TT><B>unsigned</B> char i; </TT> <BR><TT><B>unsigned</B> int j; </TT> <BR><TT>... </TT> <BR><TT>i = ((i << 4) | (i >> 4));</TT> <BR><TT>j = ((j << 8) | (j >> 8)); </TT> </BLOCKQUOTE> and generates a swap instruction for the nibble swapping<A NAME="4219"></A> or move instructions for the byte swapping<A NAME="4220"></A>. The ''j'' example can be used to convert from little to big-endian or vice versa. If you want to change the endianness of a <I>signed</I> integer you have to cast to <TT>(unsigned int)</TT> first. <P> Note that SDCC stores numbers in little-endian<A NAME="tex2html128" HREF="footnode.html#foot6122"><SUP>8.1</SUP></A><A NAME="4225"></A><A NAME="4226"></A> format (i.e. lowest order first). <P> <BR><HR> <ADDRESS> 2011-03-20 </ADDRESS> </BODY> </HTML>