Converts a Base64 character string into a binary value. The result is a MEMPTR containing the binary data.

Syntax

BASE64-DECODE ( expression )
expression
A CHARACTER or LONGCHAR expression containing the string you want to convert.
Note: The BASE64-ENCODE, BASE64-DECODE, HEX-ENCODE, and HEX-DECODE functions do not do any byte ordering. However, the binary output of these functions may be a binary data type such as a MEMPTR or RAW. If the target of these operation’s output is another system where the order of bytes (endianness) differs, you must first normalize the data to what the receiving side is expecting. Otherwise, the results may not be as expected. For example, for a MEMPTR value that you are building yourself, you can use the SET-BYTE-ORDER statement to set the byte order for the MEMPTR variable before you read or write the value.

Example

The following example codes uses the BASE64-DECODE function:

DEFINE VARIABLE memValue AS MEMPTR NO-UNDO.
DEFINE VARIABLE counter AS INTEGER NO-UNDO.

/* "Hello" encoded in Base64 */
memValue = BASE64-DECODE("SGVsbG8=").

/* Output the numeric byte values in the MEMPTR returned by BASE64-DECODE */
DO counter = 1 TO GET-SIZE(memValue):
  MESSAGE "Byte" counter ":" GET-BYTE(memValue, counter).
END.

Running this code displays the numeric byte values contained in the MEMPTR returned by BASE64-DECODE, corresponding to the decoded binary data:

Byte 1: 72
Byte 2: 101
Byte 3: 108
Byte 4: 108
Byte 5: 111

See also

BASE64-ENCODE function, SET-BYTE-ORDER statement