_Swab, _SwabL and Swab8 Commands

Purpose

Mirrors pairs of 2, 4 or 8 adjacent bytes

Syntax

_Swab src, dest, count
_SwabL src, dest, count
_Swab8 src, dest, count

src, dest, count: ivar

Description

The _Swab function copies count bytes from src, mirroring each pair of adjacent bytes, and stores the result at dest. The integer count should be a multiple of 2 to allow for swapping.

_SwabL and _Swab8 perform a similar task but mirror every 4 and 8 adjacent bytes respectively,

The _Swab commands are typically used to prepare binary data for transfer to a machine that uses a different byte order.

Example

OpenW 1

Local a As String

a = "AbCdEfGhIjKlMnOpQrStUvWxYz12"

_Swab V:a, V:a, Len(a)

Debug a    //Result: bAdCfEhGjIlKnMpOrQtSvUxWzY21

a = "AbCdEfGhIjKlMnOpQrStUvWxYz12"

_SwabL V:a, V:a, Len(a)

Debug a    //Result: dCbAhGfElKjIpOnMtSrQxWvU21zY

a = "AbCdEfGhIjKlMnOpQrStUvWxYz12"

_Swab8 V:a, V:a, Len(a)

Debug a    //Result: hGfEdCbApOnMlKjIxWvUtSrQYz12

Debug.Show

Remarks

Use Mirror to swap at the bit-level.

See Also

Mirror

{Created by Sjouke Hamstra; Last updated: 15/01/2023 by James Gaite}