Board index » delphi » Favoured approach to byte-swapping?

Favoured approach to byte-swapping?

I have an application which needs to read files produced on a machine
with 'other-endian' byte order. The file contains both 16 & 32 bit
quantities. I see from the Delphi 5 help file that the swap() function
is deprecated. What is the currently favoured approach to this? Or
should I just use swap() anyway?

Thanks

Max Hadley

 

Re:Favoured approach to byte-swapping?


On Mon, 24 Jan 2000 20:43:40 +0000, Max Hadley <m...@susato.demon.co.uk>
wrote:

Quote
>I have an application which needs to read files produced on a machine
>with 'other-endian' byte order. The file contains both 16 & 32 bit
>quantities. I see from the Delphi 5 help file that the swap() function
>is deprecated. What is the currently favoured approach to this? Or
>should I just use swap() anyway?

function Swap32(X: LongWord): LongWord; register;
asm
  bswap eax
end;

--
Ray Lischner, http://www.tempest-sw.com/nutshell
author of Delphi in a Nutshell

Re:Favoured approach to byte-swapping?


m...@zepler.org (Max Hadley) wrote in
<388CB97C.FBDA1...@susato.demon.co.uk>:

Quote
>I have an application which needs to read files produced on a machine
>with 'other-endian' byte order. The file contains both 16 & 32 bit
>quantities. I see from the Delphi 5 help file that the swap() function
>is deprecated. What is the currently favoured approach to this? Or
>should I just use swap() anyway?

for 16 bit values, use swap()

for 32 bit values, try this
Function Swap32(X : integer) : integer;
  ASM
    bswap eax
  END;

--

Mark Vaughan
____________

Visit the Numerical Methods in Pascal web page at
ftp://cloudlab.larc.nasa.gov/fNMPhome.htm

Re:Favoured approach to byte-swapping?


Im Artikel <388CB97C.FBDA1...@susato.demon.co.uk>, Max Hadley
<m...@susato.demon.co.uk> schreibt:

Quote
>I have an application which needs to read files produced on a machine
>with 'other-endian' byte order.

Most modern processors have special machine instructions for accessing or
swapping bytes of "other-endian" order.

DoDi

Other Threads