Funzione GETBIT - Amazon Redshift

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

Funzione GETBIT

GETBIT restituisce il valore in bit di un valore binario all'indice specificato.

Sintassi

GETBIT(binary_value, index)

Argomenti

binary_value

Un valore binario di tipo di dati VARBYTE.

indice

Un numero di indice del bit nel valore binario restituito. Il valore binario è un array di bit basato su 0 che viene indicizzato dal bit più a destra (bit meno significativo) al bit più a sinistra (bit più significativo).

Tipo restituito

INTEGER

Esempi

Per restituire il bit all'indice 2 del valore binario from_hex('4d'), utilizza l'esempio seguente. La rappresentazione binaria di '4d' è 01001101.

SELECT GETBIT(FROM_HEX('4d'), 2); +--------+ | getbit | +--------+ | 1 | +--------+

Per restituire il bit in otto posizioni dell'indice del valore binario restituito da from_hex('4d'), utilizza l'esempio seguente. La rappresentazione binaria di '4d' è 01001101.

SELECT GETBIT(FROM_HEX('4d'), 7), GETBIT(FROM_HEX('4d'), 6), GETBIT(FROM_HEX('4d'), 5), GETBIT(FROM_HEX('4d'), 4), GETBIT(FROM_HEX('4d'), 3), GETBIT(FROM_HEX('4d'), 2), GETBIT(FROM_HEX('4d'), 1), GETBIT(FROM_HEX('4d'), 0); +--------+--------+--------+--------+--------+--------+--------+--------+ | getbit | getbit | getbit | getbit | getbit | getbit | getbit | getbit | +--------+--------+--------+--------+--------+--------+--------+--------+ | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 1 | +--------+--------+--------+--------+--------+--------+--------+--------+