gbit

Date:

02-07-2023

NAME

_gbit, _gbits - Return the value of the nth bit (from the right)

SYNOPSIS

#include <intrinsics.h>

long _gbit (long x, long n)

long _gbits(long x, long m, long n);

STANDARDS

C extension

DESCRIPTION

The _gbit function returns the value of the nth bit (from the right) of data word x.

The _gbits function returns a value consisting of m bits extracted from x, starting at bit position n (from the right and counting to the left); the returned bits are right-justified.

These functions accept the following variables:

x

The data word from which the value is extracted.

m

A value in the range of 0 through 63.

n

A value in the range of 0 through 63.

NOTES

Because _gbit and _gbits are intrinsic functions, no externally visible library functions are available for them. The compiler generates inline code to produce the result.

EXAMPLES

Program source:

main()
{
   long x = 0x1234567890abcdef;
   printf("_gbit(x, 19) = %lx\n", _gbit(x, 19));
   printf("_gbits(x, 8, 12) = %lx\n", _gbits(x, 8, 12));
}

Execution output:

_gbit(x, 19) = 1
_gbits(x, 8, 12) = bc

SEE ALSO

For a list of C intrinsic functions, see the Cray C and C++ Reference Manual.