BITNOT - Teradata Database

SQL Functions, Operators, Expressions, and Predicates

Product
Teradata Database
Release Number
15.00
Language
English (United States)
Last Update
2018-09-24
dita:id
B035-1145
lifecycle
previous
Product Category
Teradata® Database

BITNOT

Purpose  

Performs a bitwise complement on the binary representation of the input argument.

Syntax  

where:

 

Syntax element…

Specifies…

TD_SYSFNLIB

the name of the database where the function is located.

target_arg

a numeric or variable byte expression.

ANSI Compliance

This is a Teradata extension to the ANSI SQL:2011 standard.

Description

The bitwise NOT, or complement, is a unary operation which performs logical negation on each bit, forming the ones' complement of the specified binary value. The digits in the argument which were 0 become 1, and vice versa. BITNOT returns NULL if target_arg is NULL.

Argument Types and Rules

BITNOT is an overloaded scalar function. It is defined with the following parameter data types:

  • BYTEINT
  • SMALLINT
  • INTEGER
  • BIGINT
  • VARBYTE(n)
  • The maximum supported size (n) for VARBYTE is 8192 bytes.

    All expressions passed to this function must either match these declared data types or can be converted to these types using the implicit data type conversion rules that apply to UDFs.

    Note: The UDF implicit type conversion rules are more restrictive than the implicit type conversion rules normally used by Teradata Database. If an argument cannot be converted to one of the declared data types by following UDF implicit conversion rules, it must be explicitly cast. For details, see “Compatible Types” and “Parameter Types in Overloaded Functions” in SQL External Routine Programming.

    If the argument cannot be converted to one of the declared data types, an error is returned indicating that no function exists that matches the DML UDF expression submitted.

    For more information on overloaded functions, see “Function Name Overloading” in SQL External Routine Programming.

    Result Type and Attributes

    The result data type depends on the data type of the target_arg input argument that is passed to the function as shown in the following table:

     

    IF the data type of target_arg is...

    THEN the result type is...

    AND the result format is the default format for...

    BYTEINT

    BYTEINT

    BYTEINT

    SMALLINT

    SMALLINT

    SMALLINT

    INTEGER

    INTEGER

    INTEGER

    BIGINT

    BIGINT

    BIGINT

    VARBYTE(n)

    VARBYTE(n)

    VARBYTE(n)

    The maximum supported size (n) for VARBYTE is 8192 bytes.

    The default title for BITNOT is: BITNOT(target_arg).

    For information on default data type formats, see SQL Data Types and Literals.

    Example  

    In the following query, the input argument 2 has a data type of BYTEINT and a binary representation of 00000010. Performing a BITNOT operation on this value results in a BYTEINT value of -3, or binary 11111101.

       SELECT BITNOT(2);