std::countl_zero(3)
π
std::countl_zero π
okay bestie, this one is from the C++ Standard Libary manual β yes, that spelling is literally on the page, don't come for me π. It's giving bit-counting main character energy, and it's here to count leading zeros for you, no cap π.
π NAME π
std::countl_zero - std::countl_zero
β¨ Synopsis β¨
First up, the official setup:
Defined in header <bit>
template< class T > (since C++20)
constexpr int countl_zero( T x ) noexcept;
It returns the number of consecutive 0 bits in the value of x, starting from the most significant bit β that's the "left" side, iykyk π.
This overload participates in overload resolution only if T is an unsigned integer type (that is, unsigned char, unsigned short, unsigned int, unsigned long, unsigned long long, or an extended unsigned integer type). Periodt.
πΈ Parameters πΈ
xβ value of unsigned integer type π«Ά
π¦ Return value π¦
The number of consecutive 0 bits in the value of x, starting from the most significant bit. Literally the whole vibe. β¨
β Notes β
Feature-test macro check, bestie:
__cpp_lib_bitopsβ value201907L, std(C++20), feature Bit operations π
π₯ Example π₯
This example is serving 8-bit realness β run it and see:
// Run this code
#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';
}
π Output π
countl_zero( 00000000 ) = 8
countl_zero( 11111111 ) = 0
countl_zero( 11110000 ) = 0
countl_zero( 00011110 ) = 3
π See also π
countl_one(C++20) β counts the number of consecutive1bits, starting from the most significant bit (function template) π₯countr_zero(C++20) β counts the number of consecutive0bits, starting from the least significant bit (function template) πcountr_one(C++20) β counts the number of consecutive1bits, starting from the least significant bit (function template) πΈpopcount(C++20) β counts the number of1bits in an unsigned integer (function template) βall,any,noneβ checks if all, any or none of the bits are set to true (public member function ofstd::bitset<N>) π¦
That's the tea from http://cppreference.com, version date 2024.06.10, page std::countl_zero(3) β bye bestie, slay your bit ops π
β¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms