ffs(), ffsl(), ffsll()

Updated: April 19, 2023

Find the first bit that's set in a bit string

Synopsis:

#include <strings.h>

int ffs( int value );

int ffsl( long int value );

int ffsll( long long int value );

Arguments:

value
The bit string.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The ffs(), ffsl(), and ffsll() functions find the first (least significant) bit that's set in value and return the index of that bit. Bits are numbered starting from 1, starting at the least significant bit.

Returns:

The index of the first bit that's set, or 0 if value is zero.

Classification:

ffs() is POSIX 1003.1 XSI; ffsl() and ffsll() are Unix

Safety:  
Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes