std::countl_one(3)
π std::countl_one (3) π
manual: C++ Standard Libary π
okay bestie, welcome to the C++ Standard Libary page for std::countl_one β yes, the manual name is literally βC++ Standard Libary,β and we are keeping it exactly as-is. This one is all about counting consecutive 1 bits from the left side, and itβs lowkey iconic. π¦
β¨ NAME β¨
std::countl_one - std::countl_one
β¨ Synopsis β¨
Defined in header <bit>
template< class T > (since C++20)
constexpr int countl_one( T x ) noexcept;
Returns the number of consecutive 1 ("one") bits in the value of x, starting from the most significant bit ("left"). πΈ
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).
π«Ά Parameters π«Ά
xβ value of unsigned integer type
π Return value π
The number of consecutive 1 bits in the value of x, starting from the most significant bit. No cap, thatβs just what it returns. π
π§ Notes π§
Feature-test macro vibe check:
- Feature-test macro:
__cpp_lib_bitops - Value:
201907L - Std:
(C++20) - Feature:
Bit operations
π Example π
// Run this code
#include <bit>
#include <bitset>
#include <cstdint>
#include <iostream>
int main()
{
for (const std::uint8_t i : {0, 0b11111111, 0b01111111,
0b11100011})
std::cout << "countl_one( " << std::bitset<8>(i) << " ) = "
<< std::countl_one(i) << '\n';
}
π Output π
countl_one( 00000000 ) = 0
countl_one( 11111111 ) = 8
countl_one( 01111111 ) = 0
countl_one( 11100011 ) = 3
π See also π
countl_zeroβ counts the number of consecutive0bits, starting from the most significant bit(C++20)(function template)countr_zeroβ counts the number of consecutive0bits, starting from the least significant bit(C++20)(function template)countr_oneβ counts the number of consecutive1bits, starting from the least significant bit(C++20)(function template)popcountβ counts the number of1bits in an unsigned integer(C++20)(function template)has_single_bitβ checks if a number is an integral power of 2(C++20)(function template)countβ returns the number of bits set to true (public member function ofstd::bitset<N>)allβ checks if all, any or none of the bits are set to true (public member function ofstd::bitset<N>)anyβ checks if all, any or none of the bits are set to true (public member function ofstd::bitset<N>)noneβ checks if all, any or none of the bits are set to true (public member function ofstd::bitset<N>)
okay thatβs the whole page bestie! source/version: http://cppreference.com; date: 2024.06.10; page: std::countl_one(3) β mwah πβ¨
π¦ 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