This topic describes the syntax and parameters of conversion functions. This topic also provides examples on how to use the functions.

Functions

Type Function Description
Basic type conversion ct_int Converts the value of a field or an expression to an integer.
ct_float Converts the value of a field or an expression to a floating-point number.
ct_str Converts the value of a field or an expression to a string.
ct_bool Converts the value of a field or an expression to a Boolean value.
Number conversion ct_chr Converts the ANSI or Unicode value of a field or an expression to a character.
ct_ord Converts the value of a field or an expression to an ANSI or a Unicode value.
ct_hex Converts the value of a field or an expression to a hexadecimal number.
ct_oct Converts the value of a field or an expression to an octal number.
ct_bin Converts the value of a field or an expression to a binary number.
Numeral system conversion bin2oct Converts a binary string to an octal string.
bin2hex Converts a binary string to a hexadecimal string.

ct_int

The ct_int function is used to convert the value of a field or an expression to an integer.

  • Syntax
    ct_int(value, base=10)
  • Parameters
    Parameter Type Required Description
    value Number or numeric string Yes The value that you want to convert.
    base Number No The numeral system. Default value: 10. This value indicates the decimal numeral system. If you set the base parameter to 8, this function converts an octal value to a decimal value.
  • Response

    An integer is returned.

  • Examples
    • Example 1: Convert a string to an integer.
      • Raw log entry:
        number: 2
      • Transformation rule:
        e_set("int_number", ct_int(v("number")))
      • Result:
        number: 2
        int_number:  2
    • Example 2: Convert a hexadecimal value to a decimal value.
      • Raw log entry:
        number: AB
      • Transformation rule:
        e_set("int_number", ct_int(v("number"),base=16))
      • Result:
        number: AB
        int_number:  171

ct_float

The ct_float function is used to convert the value of a field or an expression to a floating-point number.

  • Syntax
    ct_float(value)
  • Parameters
    Parameter Type Required Description
    value Number or numeric string Yes The value that you want to convert.
  • Response

    A floating-point number is returned.

  • Examples
    • Raw log entry:
      price: 2
    • Transformation rule:
      e_set("price_float", ct_float(v("price")))
    • Result:
      price: 2
      price_float:  2.0

ct_str

The ct_str function is used to convert the value of a field or an expression to a string.

  • Syntax
    ct_str(value)
  • Parameters
    Parameter Type Required Description
    value Arbitrary Yes The value that you want to convert.
  • Response

    A string is returned.

  • Example
    • Transformation rule:
      e_set("ct_str", ct_str(b'test byte'))
    • Result:
      ct_str: test byte

ct_bool

The ct_bool function is used to convert the value of a field or an expression to a Boolean value. For information about the true or false evaluation of different data types, see True or false evaluation.

  • Syntax
    ct_bool(value)
  • Parameters
    Parameter Type Required Description
    value Arbitrary Yes The value that you want to convert.
  • Response

    A Boolean value is returned.

  • Example
    • Raw log entry:
      num: 2
    • Transformation rule:
      e_set("ct_bool", ct_bool(v("num")))
    • Result:
      num: 2
      ct_bool: true

ct_chr

The ct_chr function is used to convert the ANSI or Unicode value of a field or an expression to a character.

  • Syntax
    ct_chr(value)
  • Parameters
    Parameter Type Required Description
    value Number or numeric string Yes The value that you want to convert.
  • Response

    A character is returned.

  • Example
    • Raw log entry:
      number: 78
    • Transformation rule:
      e_set("ct_chr", ct_chr(v("number")))
    • Result:
      number: 78
      ct_chr: N

ct_ord

The ct_ord function is used to convert the value of a field or an expression to an ANSI or a Unicode value.

  • Syntax
    ct_ord(value)
  • Parameters
    Parameter Type Required Description
    value String Yes The value that you want to convert. The value contains only one character.
  • Response

    An ANSI or a Unicode value is returned.

  • Example
    • Raw log entry:
      world: a
    • Transformation rule:
      e_set("ct_ord", ct_ord(v("world")))
    • Result:
      world: a
      ct_ord: 97

ct_hex

The ct_hex function is used to convert the value of a field or an expression to a hexadecimal number.

  • Syntax
    ct_hex(value)
  • Parameters
    Parameter Type Required Description
    value Number or numeric string Yes The value that you want to convert.
  • Response

    A hexadecimal number is returned.

  • Example
    • Raw log entry:
      number: 123
    • Transformation rule:
      e_set("ct_hex", ct_hex(v("number")))
    • Result:
      number: 123
      ct_hex: 0x7b

ct_oct

The ct_oct function is used to convert the value of a field or an expression to an octal number.

  • Syntax
    ct_oct(value)
  • Parameters
    Parameter Type Required Description
    value Number or numeric string Yes The value that you want to convert.
  • Response

    An octal number is returned.

  • Example
    • Raw log entry:
      number: 123
    • Transformation rule:
      e_set("ct_oct", ct_oct(v("number")))
    • Result:
      number: 123
      ct_oct: 0o173

ct_bin

The ct_bin function is used to convert the value of a field or an expression to a binary number.

  • Syntax
    ct_bin(value)
  • Parameters
    Parameter Type Required Description
    value Number or numeric string Yes The value that you want to convert.
  • Response

    A binary number is returned.

  • Example
    • Raw log entry:
      number: 123
    • Transformation rule:
      e_set("ct_bin", ct_bin(v("number")))
    • Result:
      number: 123
      ct_bin: 0b1111011

bin2oct

The bin2oct function is used to convert a binary string to an octal string.

  • Syntax
    bin2oct(binary)
  • Parameters
    Parameter Type Required Description
    binary Binary Yes The binary string that you want to convert.
  • Response

    An octal string is returned.

  • Example
    • Raw log entry:
      test : test
    • Transformation rule:
      e_set("new",bin2oct(base64_decoding("ARi8WnFiLAAACHcAGgkADV37Xs8BXftezgAdqwF9")))
    • Result:
      test : test
      new : 214274264705421300000002073400064044000325677327547401273755366340003552600575

bin2hex

The bin2hex function is used to convert a binary string to a hexadecimal string.

  • Syntax
    bin2hex(binary)
  • Parameters
    Parameter Type Required Description
    binary Binary Yes The binary string that you want to convert.
  • Response

    A hexadecimal string is returned.

  • Example
    • Raw log entry:
      test : test
    • Transformation rule:
      e_set("new",bin2hex(base64_decoding("ARi8WnFiLAAACHcAGgkADV37Xs8BXftezgAdqwF9")))
    • Result:
      test : test
      new :0118bc5a71622c00000877001a09000d5dfb5ecf015dfb5ece001dab017d