名前空間
変種
操作

std::countr_one

提供: cppreference.com
< cpp‎ | numeric
ヘッダ <bit> で定義
template<class T>
constexprint countr_one(T x)noexcept;
(C++20以上)

x の値の中の最下位ビット (右) からの連続する1のビットの数を返します。

このオーバーロードは、T が符号なし整数型 (すなわち unsignedcharunsignedshortunsignedintunsignedlongunsignedlonglong、または拡張符号なし整数型) である場合にのみ、オーバーロード解決に参加します。

目次

[編集]引数

x - 符号なし整数型の値

[編集]戻り値

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<<"countr_one(0b"<<std::bitset<8>(i)<<") = "<< std::countr_one(i)<<'\n';}}

出力:

countr_one(0b00000000) = 0 countr_one(0b11111111) = 8 countr_one(0b11100011) = 2

[編集] 関連項目

最上位ビットから連続する0のビットの数を数えます
(関数テンプレート)[edit]
(C++20)
最上位ビットから連続する1のビットの数を数えます
(関数テンプレート)[edit]
最下位ビットから連続する0のビットの数を数えます
(関数テンプレート)[edit]
(C++20)
符号なし整数の1のビットの数を数えます
(関数テンプレート)[edit]
close