Bswap Function

Purpose

The Bswap() functions change the byte order of integer values.

Syntax

i% = Bswap[%](x)i, x : ivar

i& = Bswap&(x)i&: word, x : ivar

i% = Bswap3(x)i, x : ivar

i = Bswap8(x)i: Int64, x : ivar

Description

Bswap[%] changes the order of a 32 bit-Integer; Bswap(0x12345678) returns 0x78563412 (0x means Hex-literal).

Bswap& changes the order of a 16 bit-Integer; Bswap&(iexp) = Rol&(iexp, 8).

Bswap3 changes the order of the lower 3 bytes. This could be useful in converting BGR color values to (Blue-Green-Red) in RGB-values.

Bswap8 changes the order of a 64 bit-integer or Large.

Example

Print Hex$(Bswap%(0x12345678)) // 78563412

Print Hex$(Bswap&(0x12345678)) // 7856

Print Hex$(Bswap3(0x12345678)) // 785634

Print Hex$(Bswap8(0x12345678)) // 7856341200000000

Remarks

Bswap and Bswap% are identical. Bswap is a shortcut for:

MakeLongHiLo(Rol&(LoWord(i), 8), Rol&(HiWord(i), 8))

Bswap8 is a shortcut for:

Print MakeLargeHiLo( _

MakeLongHiLo(Rol&(LoWord(i64), 8), Rol&(HiWord(i64), 8)), _

MakeLongHiLo(Rol&(LoWord(HiLarge(i64)), 8), Rol&(HiWord(HiLarge(i64)), 8)) _

)

Alternatively (but slower):

Cv8(Mirror$(Mk8(i64)))

See Also

{Created by Sjouke Hamstra; Last updated: 24/09/2014 by James Gaite}