Element: blob.byteswap ( )

Syntax

<ident> = <blob>.byteswap(<num> {,<range> ...})

   or

<blob>.byteswap(<num> {,<range> ...})

Type

blob or procedure

Description

A function which swaps bytes within the blob.

If called as part of a blob assignment or expression, the return value of this function is a copy of the blob with the relevant bytes swapped. The whole blob is returned, not just the bytes which have been swapped. The original blob is left unchanged.

If called stand-alone, there is no return value but the blob has the bytes swapped in place.

Byte-swapping reverses the order of byte values according to the value of the first parameter num, which can have the value 2,4 or 8. Consider a sequence of byes ABCDEFGHIJKLMNOP. The following table shows the results for different values of num.

num

Result

-

AB CD EF GH IJ KL MN OP

2

BA DC FE HG JI LK NM PO

4

DC BA HG FE LK JI PO NM

8

HG FE DC BA PO NM LK JI

The other parameters to this function are one or more byte ranges. Each range is in the form startbyte:endbyte. The ranges are comma-separated and do not have to be consecutive in byte order, but each range should be a multiple of num. Omitting the range parameters implies that all bytes are to be swapped.

The code of this function cannot be redefined.

Examples

Byte-swap by 2 all bytes in a blob:

myblob.byteswap(2)

Byte-swap by 4 a range of 100 bytes, and return the result into another blob:

blob newblob = myblob.byteswap(4,1:100)

See Also

Commands:

blob

Structures:

blob, blob.bitswap, blob.invert