tencent cloud

masukan

Bitwise Operation

Terakhir diperbarui:2024-01-22 10:52:48
    This document introduces the basic syntax and examples of bitwise operation functions.
    Function
    Syntax
    Description
    bit_count(x, bits)
    Returns the number of ones in x in binary representation.
    bitwise_and(x, y)
    Returns the result of the bitwise AND operation on x and y in binary representation.
    bitwise_not(x)
    Inverts all bits of x in binary representation.
    bitwise_or(x, y)
    Returns the result of the bitwise OR operation on x and y in binary representation.
    bitwise_xor(x, y)
    Returns the result of the bitwise XOR operation on x and y in binary representation.

    bit_count

    The bit_count function is used to return the number of ones in x.

    Syntax

    bit_count(x, bits)

    Parameter description

    Parameter
    Description
    x
    The parameter value is of the bigint type.
    bits
    Number of bits, for example, 64 bits.

    Return value type

    Bigint

    Example

    Compute the binary representation of the number 24 and return the number of ones in the binary number.
    Query and analysis statement
    * | SELECT bit_count(24, 64)
    Query and analysis result
    2

    bitwise_and

    The bitwise_and function is used to return the result of the bitwise AND operation on x and y in binary representation.

    Syntax

    bitwise_and(x, y)

    Parameter description

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

    Return value type

    Bigint

    Example

    Perform an AND operation on numbers 3 and 5 in binary form.
    Query and analysis statement
    * | SELECT bitwise_and(3, 5)
    Query and analysis result
    1

    bitwise_not

    The bitwise_not function is used to invert all bits of x in binary representation.

    Syntax

    bitwise_not(x)

    Parameter description

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

    Return value type

    Bigint

    Example

    Invert all bits of the number 4 in binary form.
    Query and analysis statement
    * | SELECT bitwise_not(4)
    Query and analysis result
    -5

    bitwise_or

    The bitwise_or function is used to return the result of the bitwise OR operation on x and y in binary representation.

    Syntax

    bitwise_or(x, y)

    Parameter description

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

    Return value type

    Bigint

    Example

    Perform an OR operation on numbers 3 and 5 in binary representation.
    Query and analysis statement
    * | SELECT bitwise_or(3, 5)
    Query and analysis result
    7

    bitwise_xor

    The bitwise_xor function is used to return the result of the bitwise XOR operation on x and y in binary representation.

    Syntax

    bitwise_xor(x, y)

    Parameter description

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

    Return value type

    Bigint

    Example

    Perform an XOR operation on numbers 3 and 5 in binary representation.
    Query and analysis statement
    * | SELECT bitwise_xor(3, 5)
    Query and analysis result
    6
    
    Hubungi Kami

    Hubungi tim penjualan atau penasihat bisnis kami untuk membantu bisnis Anda.

    Dukungan Teknis

    Buka tiket jika Anda mencari bantuan lebih lanjut. Tiket kami tersedia 7x24.

    Dukungan Telepon 7x24