Appearance
GETBIT Function
Return the bit value (0
or 1
) in a number at the specified position, according to the binary representation of that number.
getbit(target_number, bit_position)
- target_number
- A specific number or an expression that evaluates to a number. The number must be a
SMALLINT
,INT
, orBIGINT
data type. - bit_position
- Bit position in the target number. The position must be an integer that is in range for the size of the target number. For example, if the target is a 16-bit data type, the position must be between
0
and15
. For a 32-bit data type, the position must be between0
and31
.
For example:
premdb=# select htid, getbit(htid,2) from team;
htid | getbit
------+--------
2 | 0
3 | 0
4 | 1
5 | 1
6 | 1
7 | 1
8 | 0
9 | 0
10 | 0
...
premdb=# select getbit(987654321,31) from sys.const;
getbit
--------
0
(1 row)