std::countl_one - cppreference.com
提供: cppreference.com
<tbody> </tbody>
|
|
(C++20以上) | |
x の値の中の最上位ビット (左) からの連続する1のビットの数を返します。
このオーバーロードは、T が符号なし整数型 (すなわち unsigned char、 unsigned short、 unsigned int、 unsigned long、 unsigned long long、または拡張符号なし整数型) である場合にのみ、オーバーロード解決に参加します。
引数
戻り値
x の値の中の最上位ビットからの連続する1のビットの数。
例
#include <bit> #include <bitset> #include <cstdint> #include <initializer_list> #include <iostream> int main() { for (std::uint8_t i : { 0, 0b11111111, 0b11100011 }) { std::cout << "countl_one(0b" << std::bitset<8>(i) << ") = " << std::countl_one(i) << '\n'; } }
出力:
countl_one(0b00000000) = 0 countl_one(0b11111111) = 8 countl_one(0b11100011) = 3