For the latest version of JMP Help, visit JMP.com/help.


Scripting Guide > Types of Data > Hexadecimal and BLOB Functions
Publication date: 11/10/2021

Hexadecimal and BLOB Functions

JMP can also handle binary (large) objects, commonly called BLOBs. The functions below convert between hexadecimal values, numbers, characters, and BLOBs. Some of the functions are covered in more detail following Table 6.7.

See Character Functions in the JSL Syntax Reference for more information.

Table 6.7 Hexadecimal and BLOB Functions

Syntax

Explanation

Hex("text")

Hex("num")

Hex("blob")

Returns the hexadecimal codes for the characters in text, number, or blob.

Char To Hex is an alias.

Hex To BLOB("hexstring")

Returns a BLOB representation of the hexadecimal code supplied as a quoted string.

Hex To Char("hexstring", "encoding")

Returns a character string that corresponds to the hexadecimal code supplied as a quoted string.

The default encoding for the character string is utf-8. utf-16le, utf-16be, us-ascii, iso-8859-1, ascii~hex, shift-jis, and euc-jp are also supported.

Hex to Number

Returns the number that corresponds to the hexadecimal code suppled as a quoted string.

Char To BLOB("string")

Char To BLOB("string", "encoding")

Converts a character string into a binary (BLOB).

The default encoding for the blob is utf-8. utf-16le, utf-16be, us-ascii, iso-8859-1, ascii~hex, shift-jis, and euc-jp are also supported.

BLOB To Char("blob")

BLOB To Char("blob", "encoding")

Converts binary data to a character string.

The default encoding for the character string is utf-8. utf-16le, utf-16be, us-ascii, iso-8859-1, ascii~hex, shift-jis, and euc-jp are also supported.

BLOB Peek("blob", offset, length)

Returns a new BLOB that is a subset of the given BLOB that is length bytes long and begins at the offset. Note that the offset is 0-based.

Matrix to BLOB(matrix, type, bytesEach, endian)

Makes a BLOB from a matrix by converting the matrix elements to 1-byte, 2-byte, or 4-byte signed or unsigned integers or 4-byte or 8-byte floating point numbers.

BLOB to Matrix(blob, "type", bytes, "endian", <nCols>)

Creates a matrix by converting each byte in the blob to numbers.

Hex(string) returns the hexadecimal codes for each character in the argument. For example,

Hex( "Abc" );

returns

"416263"

since 41, 62, and 63 are the hexadecimal codes (in ASCII) for “A”, “b”, and “c”.

Hex to Char(string) converts hexadecimal to characters. The resulting character string might not be valid display characters. All the characters must be in pairs, in the ranges 0-9, A-Z, and a-z. Blanks and commas are allowed, and skipped. For example,

Hex To Char( "4142" );

returns

"AB"

since 41 and 42 are the hexadecimal equivalents of “A” and “B”.

Hex and Hex To Char are inverses of each other, so

Hex To Char( Hex( "Abc" ) );

returns

"Abc"

Hex To BLOB(string) takes a string of hexadecimal codes and converts it to a binary object.

a = Hex To BLOB( "6A6B6C" );
Show( a );

a = Char To BLOB("jkl", "ascii~hex")

BLOB Peek(blob,offset,length) extracts bytes as defined by the arguments from a blob.

b = BLOB Peek( a, 1, 2 );
Show( b );

b = Char To BLOB("kl", "ascii~hex")

b = BLOB Peek( a, 0, 2 );
Show( b );

b = Char To BLOB("jk", "ascii~hex")

b = BLOB Peek( a, 2 );
Show( b );

b = Char To BLOB("l", "ascii~hex")

Hex(blob) converts a blob into hexadecimal.

c = Hex( a );
Show( c );

c = "6A6B6C"

d = Hex To Char( c );
Show( d );

d = "jkl"

Concat(blob1,blob2) or blob1 || blob2 concatenates two blobs.

e = Hex To BLOB( "6D6E6F" );
Show( e );
f = a||e;
Show( f );

e = Char To BLOB("mno", "ascii~hex")

f = Char To BLOB("jklmno", "ascii~hex")

Length(blob) returns the number of bytes in a blob.

g = Length( f );
Show( g );

g = 6

Note: When blobs are listed in the log, they are shown with the constructor function Char To BLOB("...").

Any hex code outside the ASCII range (space to }, or hex 20 - 7D) is encoded as the three-character sequence [~][hexdigit][hexdigit]. For example,

h = Hex To BLOB( "19207D7E" );
Show( h );
i = Hex( h );
Show( i );

h = Char To BLOB("~19 }~7E", "ascii~hex")

i = "19207D7E"

Char To BLOB(string) creates a blob from a string, converting ~hex codes. BLOB To Char(blob) creates a string with ~hex codes to indicate non-visible and non-ASCII codes.

Want more information? Have questions? Get answers in the JMP User Community (community.jmp.com).