From: Keith Hull Newsgroups: comp.os.msdos.djgpp Subject: Re: big endian class Date: Sun, 1 Jun 1997 16:28:26 +0100 Message-ID: <1997060116282677565@zetnet.co.uk> References: <338F1A19 DOT 474E AT blackmagic DOT tait DOT co DOT nz> <5mpb7b$3nm$1 AT news0 DOT xs4all DOT nl> NNTP-Posting-Host: crescent.zetnet.co.uk Lines: 43 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk In message <5mpb7b$3nm$1 AT news0 DOT xs4all DOT nl> ellman AT xs4all DOT nl () writes: > In article <338F1A19 DOT 474E AT blackmagic DOT tait DOT co DOT nz>, > Bill Currie wrote: > >If anyone can figure a better way of byte swapping longs (without useing > >bswap), preferably in c, please let me know as gcc can't optimise > >swapBytes(long) or swapBytes(ulong) when called with constants (due to > >the assembly code). > void swapbytes(long *the_variable) > { > register char b0,b1,b2,b3; > b0 = *(((char *)(the_variable))); > b1 = *(((char *)(the_variable))+1); > b2 = *(((char *)(the_variable))+2); > b3 = *(((char *)(the_bariable))+3); > *(((char *)(the_variable))) = b3; > *(((char *)(the_variable))+1) = b2; > *(((char *)(the_variable))+2) = b1; > *(((char *)(the_variable))+3) = b0; > } > If you have some means of detecting wether your program will be comipled for a > 486, use inline assembly with the bswap instruction. or dummy = (data & 0x000000ff) << 24; dummy = dummy | ((data & 0x0000ff00) << 8); dummy = dummy | ((data & 0x00FF0000) >> 8); dummy = dummy | ((data & 0xFF000000) >> 24); -- Keith Hull - Bournemouth keithh AT zetnet DOT co DOT uk keithh AT yeomanh DOT spsxch DOT p4 DOT sps DOT co DOT uk