tencent cloud

피드백

Bitwise Operation

마지막 업데이트 시간: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
    
    문의하기

    고객의 업무에 전용 서비스를 제공해드립니다.

    기술 지원

    더 많은 도움이 필요하시면, 티켓을 통해 연락 바랍니다. 티켓 서비스는 연중무휴 24시간 제공됩니다.

    연중무휴 24시간 전화 지원