BIT_TEST
Descriptionβ
Convert the value of <x>
to binary form and return the value of the specified position <bits>
, where <bits>
starts from 0 and goes from right to left.
If <bits>
has multiple values, the values at multiple <bits>
positions are combined using the AND operator and the final result is returned.
If the value of <bits>
is negative or exceeds the total number of bits in <x>
, the result will be 0.
Integer <x>
range: TINYINT, SMALLINT, INT, BIGINT, LARGEINT.
Aliasβ
- BIT_TEST_ALL
Syntaxβ
BIT_TEST( <x>, <bits>[, <bits> ... ])
Parametersβ
parameter | description |
---|---|
<x> | The integer to be calculated |
<bits> | The value at the specified position |
Return Valueβ
Returns the value at the specified position
Examplesβ
select BIT_TEST(43, 1), BIT_TEST(43, -1), BIT_TEST(43, 0, 1, 3, 5,2);
+-----------------+------------------+-----------------------------+
| bit_test(43, 1) | bit_test(43, -1) | bit_test(43, 0, 1, 3, 5, 2) |
+-----------------+------------------+-----------------------------+
| 1 | 0 | 0 |
+-----------------+------------------+-----------------------------+