This topic describes the syntax of binary functions. This topic also provides examples on how to use the functions.

Notice
  • If you want to use strings in analytic statements, you must enclose the strings in single quotation marks (''). Strings that are not enclosed or are enclosed in double quotation marks ("") are considered field names or column names. For example, 'status' is considered the status string, and status or "status" is considered a log field whose name is status.
  • varbinary is a binary character type, and varchar is a variable-length character type.
Function Syntax Description
concat function concat(x,y...) Returns the concatenation of multiple binary numbers.
from_base64 function from_base64(x) Decodes a Base64-encoded string into a binary number.
from_base64url function from_base64url(x) Decodes a Base64-encoded string into a binary number by using URL reserved characters.
from_big_endian_64 function from_big_endian_64(x) Decodes a binary number in big endian into a bigint value.
from_hex function from_hex(x) Decodes a hexadecimal number into a binary number.
length function length(x) Returns the length of a binary number.
md5 function md5(x) Computes the MD5 hash value for a binary number.
to_base64 function to_base64(x) Encodes a binary number into a Base64 string representation.
to_base64url function to_base64url(x) Encodes a binary number into a Base64 string representation by using URL reserved characters.
to_hex function to_hex(x) Encodes a binary number into a hexadecimal number.
to_big_endian_64 function to_big_endian_64(x) Encodes a bigint value into a binary number in big endian.
sha1 function sha1(x) Computes the SHA-1 hash value for a binary number.
sha256 sha256(x) Computes the SHA-256 hash value for a binary number.
sha512 function sha512(x) Computes the SHA-512 hash value for a binary number.
xxhash64 function xxhash64(x) Computes the xxhash64 hash value for a binary number.

concat function

The concat function returns the concatenation of multiple binary numbers.

Syntax

concat(x,y...)

Parameters

Parameter Description
x The value of this parameter is of the binary type.
y The value of this parameter is of the binary type.

Return value type

The varbinary type.

Examples

Concatenate the binary numbers 10 and 11 by using a space.

  • Query statement
    * | SELECT concat('10',' ','11')
  • Query and analysis resultsconcat

from_base64 function

The from_base64 function decodes a Base64-encoded string into a binary number.

Syntax

from_base64(x)

Parameters

Parameter Description
x The value of this parameter is of the binary type.

Return value type

The varbinary type.

Notice The return value of the varbinary type contains invisible characters and is displayed in the Base64-encoded format.
  • If the returned binary number is an invisible character, you can use the to_hex function to encode the number into a hexadecimal number.
  • If the returned binary number is a visible character, you can use the from_utf8 function to encode the number into a UTF-8 string.

Examples

Decode a Base64-encoded string into a binary number and then encode the binary number into a hexadecimal number.

  • Query statement
    * | SELECT to_hex(from_base64('c2xz'))
  • Query and analysis resultsfrom_base64

from_base64url function

The from_base64url function decodes a Base64-encoded string into a binary number by using URL reserved characters.

Syntax

from_base64url(x)

Parameters

Parameter Description
x The value of this parameter is of the binary type.

Return value type

The varbinary type.
Notice The return value of the varbinary type contains invisible characters and is displayed in the Base64-encoded format.
  • If the returned binary number is an invisible character, you can use the to_hex function to encode the number into a hexadecimal number.
  • If the returned binary number is a visible character, you can use the from_utf8 function to encode the number into a UTF-8 string.

Examples

Decode a Base64-encoded string into a binary number by using URL reserved characters.

  • Query statement
    * | SELECT to_hex(from_base64url('c2xz'))
  • Query and analysis resultsfrom_base64

from_big_endian_64 function

The from_big_endian_64 function decodes a binary number in big endian into a bigint value.

Syntax

from_big_endian_64(x)

Parameters

Parameter Description
x The value of this parameter is of the binary type.

Return value type

The bigint type.

Examples

Decode the binary number 10 in big endian into a bigint value.

  • Query statement
    * | SELECT from_big_endian_64(to_big_endian_64(10))
  • Query and analysis resultsfrom_big_endian_64

from_hex function

The from_hex function decodes a hexadecimal number into a binary number.

Syntax

from_hex(x)

Parameters

Parameter Description
x The value of this parameter is of the varbinary type.

Return value type

The varbinary type.

Examples

Decode the hexadecimal number D74D into a binary number.

  • Query statement
    * | SELECT from_hex('D74D')
  • Query and analysis resultsfrom_hex

length function

The length function returns the length of a binary number.

Syntax

length(x)

Parameters

Parameter Description
x The value of this parameter is of the binary type.

Return value type

The bigint type.

Examples

Calculate the length of the region field value.

  • Query statement
    * | SELECT length('00101000')
  • Query and analysis resultslength

md5 function

The md5 function computes the MD5 hash value for a binary number.

Syntax

md5(x)

Parameters

Parameter Description
x The value of this parameter is of the varbinary type.

Return value type

The varbinary type.

Examples

Compute the MD5 hash value for the binary number 1101.

  • Query statement
    * | SELECT MD5(from_base64('1101')) AS md5
  • Query and analysis resultsMD5

to_base64 function

The to_base64 function encodes a binary number into a Base64 string representation.

Syntax

to_base64(x)

Parameters

Parameter Description
x The value of this parameter is of the binary type.

Return value type

The varchar type.

Examples

Encode the binary number 10 into a Base64 string representation.

  • Query statement
    * | SELECT  to_base64(from_base64('10')) AS base64
  • Query and analysis resultsto_base64

to_base64url function

The to_base64url function encodes a binary number into a Base64 string representation by using URL reserved characters.

Syntax

to_base64url(x)

Parameters

Parameter Description
x The value of this parameter is of the binary type.

Return value type

The varchar type.

Examples

Encode the binary number 100 into a Base64 string representation by using URL reserved characters.

  • Query statement
    * | SELECT  to_base64url(from_base64('100'))
  • Query and analysis results to_base64url

to_hex function

The to_hex function encodes a binary number into a hexadecimal number.

Syntax

to_hex(x)

Parameters

Parameter Description
x The value of this parameter is of the binary type.

Return value type

The varchar type.

Examples

Encode the binary number 100 into a hexadecimal number.

  • Query statement
    * | SELECT to_hex(from_base64('100'))
  • Query and analysis resultsto_hex

to_big_endian_64 function

The to_big_endian_64 function encodes a bigint value into a binary number in big endian.

Syntax

to_big_endian_64(x)

Parameters

Parameter Description
x The value of this parameter is of the bigint type.

Return value type

The varbinary type.

Examples

Encode the bigint value 0 into a binary number in big endian.

  • Query statement
    * | SELECT to_big_endian_64(0)
  • Query and analysis resultsto_big_endian_64

sha1 function

The sha1 function computes the SHA-1 hash value for a binary number.

Syntax

sha1(x)

Parameters

Parameter Description
x The value of this parameter is of the binary type.

Return value type

The varbinary type.

Examples

Compute the SHA-1 hash value for the binary number 1101.

  • Query statement
    * | SELECT sha1(from_base64('1101')) AS sha1
  • Query and analysis resultssha1

sha256

The sha256 function computes the SHA-256 hash value for a binary number.

Syntax

sha256(x)

Parameters

Parameter Description
x The value of this parameter is of the binary type.

Return value type

The varbinary type.

Examples

Compute the SHA-256 hash value for the binary number 1101.

  • Query statement
    * | SELECT sha256(from_base64('1101')) AS sha256
  • Query and analysis resultssha256

sha512 function

The sha512 function computes the SHA-512 hash value for a binary number.

Syntax

sha512(x)

Parameters

Parameter Description
x The value of this parameter is of the binary type.

Return value type

The varbinary type.

Examples

Compute the SHA-512 hash value for the binary number 1101.

  • Query statement
    * | SELECT sha512(from_base64('1101')) AS sha512
  • Query and analysis resultssha512

xxhash64 function

The xxhash64 function computes the xxhash64 hash value for a binary number.

Syntax

xxhash64(x)

Parameters

Parameter Description
x The value of this parameter is of the binary type.

Return value type

The varbinary type.

Examples

Compute the xxhash64 hash value for the binary number 10.

  • Query statement
    * | SELECT xxhash64(from_base64('10'))
  • Query and analysis resultsxxhash64