SWP
Byte Swap
This string function performs up to three predefined byte-swapping functions on a string.
Syntax
Section titled “Syntax”SWP ( string-value, swap-option [,ERR=line-ref|,ERC=error-code])string-value- is a string
swap-option- is a one-byte character whose least-significant three bits determine which byte-swapping functions are to be performed.
line-ref- is the program line number or label to branch to if an error is produced by this function.
error-code- is a programmer-defined error code. Valid values are positive or negative whole numbers.
Remarks
Section titled “Remarks”This function is generally available starting with release level 8.1.
The interpretation of the least-significant three bits in swap-option are:
bit 0 (rightmost bit) = swap adjacent bytes bit 1 = swap adjacent 2-byte words bit 2 = swap adjacent 4-byte long words.
The simplest way to represent swap-option is to use the characters 0 through 7. 0 performs no swapping; all odd numbers swap adjacent bytes (1,3,5,7); 2-byte swaps are performed for 2,3,6,7; and 4-byte swaps are performed for 4,5,6,7. Note that swapping functions compound: a swap-option of 7 performs all three swapping operations.
Byte swapping starts at the left-most position of string-value, and continues toward the right as long as there are sufficient bytes for the operation. In other words, adjacent byte swaps require two bytes, adjacent 2-byte swaps require four bytes, and adjacent 4-byte swaps require 8 bytes (see the examples below for further explanation).
Examples
Section titled “Examples”LET STRING$ = "1234567812345678"PRINT SWP ( STRING$, SWAP_OPTION$ )produces the following strings for the given SWAP_OPTION$ values:
“0” produces “1234567812345678”. “1” produces “2143658721436587”. “2” produces “3412785634127856”. “3” produces “4321876543218765”. “4” produces “5678123456781234”. “5” produces “6587214365872143”. “6” produces “7856341278563412”. “7” produces “8765432187654321”.
From the Thoroughbred Basic Language Reference, Volume III: R–Z, version 8.9.1. Open this page in the PDF