Base64Encode (Encode/Decode)

Base64 is a binary-to-text encoding method that represents binary data using a set of 64 printable ASCII characters. It is designed to safely transmit binary data—such as images or files—over systems that only support text. This instruction is available in operating system 6.2 or newer.

Syntax

Base64Encode ( ReturnCode, EncodeDecodeFlag, SourceBuff, SourceOffset, SourceSwath, DestBuff, DestSize )

Remarks

Base64 is a binary-to-text encoding method that represents binary data using a set of 64 printable ASCII characters. It is designed to safely transmit binary data—such as images or files—over systems that only support text.

How Base64 works:

  • Encodes binary data to text (a readable ASCII string).

  • This allows binary files to be sent through channels such as email and HTTP, which were originally designed for plain text.

  • The encoding process adds overhead, increasing the size of the encoded data by about 33–37%.

Common uses for Base64:

  • Email attachments: Older email protocols were text-only and could corrupt binary attachments.

  • Web development: Images and other small assets can be embedded directly into HTML or CSS files using a Base64 data URL.

  • HTTP authentication: Usernames and passwords in HTTP basic authentication are Base64 encoded.

  • JSON Web Tokens: The components of a JWT are Base64 encoded.

Parameters

ReturnCode

The variable in which a return code for the transmission will be stored. The codes that can be returned are:

Code Description
0 Successful.
-1 Failed. DestBuff too small. (In this case, the required destination buffer size is stored into DestSize.)
-2 Failed. Invalid character. (This can only happen on decode.)
-3 Invalid SourceOffset, (SourceOffset must be >= 0 AND < SourceBuff size.)
-4 Invalid SourceSwath. (SourceSwath must NOT go out of bounds, including if the SourceOffset makes it go out of bounds.)

Type: Variable (Long or Float)

EncodeDecodeFlag

Determines if an encode or decode is performed.

Code Description
0 Encode

1 (or any non-zero value)

Decode

Type: Constant or Variable (Long, Float, or Boolean)

SourceBuff (Source Buffer)

The input/source data buffer to operate on.

Type: Any (usually a string)

SourceOffset (Source Offset)

Offset, in bytes, into SourceBuff to start at. Leave at '0' to start at the beginning of the buffer.

Type: Constant or Variable (Long or Float)

SourceSwath (Source Swath)

Number of bytes in SourceBuff to encode/decode. Leave at '0' to encode/decode the whole buffer (from the specified SourceOffset to the end of its own memory).

Type: Constant or Variable (Long or Float)

DestBuff (Destination Data Buffer)

The output/destination data buffer to store the result into.

Type: Variable (usually a string)

DestSize (Destination Size)

Number of bytes written to the DestBuff during operation

Type: Variable (Long or Float)