ffs() — Find first set bit in an integer

Standards

Standards / Extensions C or C++ Dependencies

XPG4.2
Single UNIX Specification, Version 3

both  

Format

#define  _XOPEN_SOURCE_EXTENDED 1
#include <strings.h>

int ffs(int i);

General description

The ffs() function finds the first bit set (beginning with the least significant bit) and returns the index of that bit. Bits are numbered starting at one (the least significant bit).

Returned value

If successful, ffs() returns the index of the first bit set.

If i is 0, ffs() returns 0.

There are no errno values defined.

Related information