标准库标头 <bit>

来自cppreference.com
< cpp‎ | header


 
 
标准库头
通用工具
<any> (C++17)
<bitset>
<bit> (C++20)
<charconv> (C++17)
<expected> (C++23)
<format> (C++20)
<functional>
<optional> (C++17)
<stdbit.h> (C++26)
<tuple> (C++11)
<typeindex> (C++11)
<utility>
<variant> (C++17)
容器
<array> (C++11)
<deque>
<flat_map> (C++23)
<flat_set> (C++23)
<forward_list> (C++11)
<hive> (C++26)
<inplace_vector> (C++26)   
<list>
<map>
<mdspan> (C++23)
<queue>
<set>
<span> (C++20)
<stack>
<unordered_map> (C++11)
<unordered_set> (C++11)
<vector>
迭代器
<iterator>
范围
<generator> (C++23)
<ranges> (C++20)
 

此头文件是数值库的一部分。

类型

(C++20)
指示标量类型的端序
(枚举) [编辑]

函数

(C++20)
重解释类型的对象表示为另一类型的对象表示
(函数模板) [编辑]
(C++23)
反转给定整数中的字节
(函数模板) [编辑]
检查一个数是否为 2 的整数次幂
(函数模板) [编辑]
(C++20)
寻找不小于给定值的最小的 2 的整数次幂
(函数模板) [编辑]
(C++20)
寻找不大于给定值的最大的 2 的整数次幂
(函数模板) [编辑]
(C++20)
寻找表示给定值所需的最小位数
(函数模板) [编辑]
(C++20)
计算逐位左旋转的结果
(函数模板) [编辑]
(C++20)
计算逐位右旋转的结果
(函数模板) [编辑]
从最高位起计量连续的 0 位的数量
(函数模板) [编辑]
从最高位起计量连续的 1 位的数量
(函数模板) [编辑]
从最低位起计量连续的 0 位的数量
(函数模板) [编辑]
从最低位起计量连续的 1 位的数量
(函数模板) [编辑]
(C++20)
计量无符号整数中为 1 的位的数量
(函数模板) [编辑]

[编辑] 概要

namespace std {
  // bit_­cast
  template<class To, class From>
    constexpr To bit_cast(const From& from) noexcept;
 
  // byteswap
  template <class T>
    constexpr T byteswap(T value) noexcept;
 
  // 2 的整数次幂
  template<class T>
    constexpr bool has_single_bit(T x) noexcept;
  template<class T>
    constexpr T bit_ceil(T x);
  template<class T>
    constexpr T bit_floor(T x) noexcept;
  template<class T>
    constexpr int bit_width(T x) noexcept;
 
  // 旋转
  template<class T>
    constexpr T rotl(T x, int s) noexcept;
  template<class T>
    constexpr T rotr(T x, int s) noexcept;
 
  // 计数
  template<class T>
    constexpr int countl_zero(T x) noexcept;
  template<class T>
    constexpr int countl_one(T x) noexcept;
  template<class T>
    constexpr int countr_zero(T x) noexcept;
  template<class T>
    constexpr int countr_one(T x) noexcept;
  template<class T>
    constexpr int popcount(T x) noexcept;
 
  // 端序
  enum class endian {
    little = /* 见描述 */,
    big    = /* 见描述 */,
    native = /* 见描述 */
  };
}