std::countl_zero

Header: <bit>

Returns the number of consecutive 0 bits in the value of x, starting from the most significant bit (“left”).

# Declarations

template< class T >
constexpr int countl_zero( T x ) noexcept;

(since C++20)

# Parameters

# Return value

The number of consecutive 0 bits in the value of x, starting from the most significant bit.

# Notes

Feature-test macro Value Std Feature __cpp_lib_bitops 201907L (C++20) Bit operations

# Example

#include <bit>
#include <bitset>
#include <cstdint>
#include <iostream>
 
int main()
{
    for (const std::uint8_t i : {0, 0b11111111, 0b11110000, 0b00011110})
        std::cout << "countl_zero( " << std::bitset<8>(i) << " ) = "
                  << std::countl_zero(i) << '\n';
}

# See also