Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

GETBIT function

Focus mode
GETBIT function - Amazon Redshift

GETBIT returns the bit value of a binary value at the specified index.

Syntax

GETBIT(binary_value, index)

Arguments

binary_value

A binary value of data type VARBYTE.

index

An index number of the bit in the binary value that is returned. The binary value is a 0-based bit array that is indexed from the rightmost bit (least significant bit) to the leftmost bit (most significant bit).

Return type

INTEGER

Examples

To return the bit at index 2 of the binary value from_hex('4d'), use the following example. The binary representation of '4d' is 01001101.

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

To return the bit at eight index locations of the binary value returned by from_hex('4d'), use the following example. The binary representation of '4d' is 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 | +--------+--------+--------+--------+--------+--------+--------+--------+

On this page

PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.