MSTL 1.4.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
位操作函数

位宽计算、位取整和位检查函数 更多...

函数

constexpr int bit_width (const uintptr_t x) noexcept
 计算表示整数所需的最小位宽
constexpr uintptr_t bit_floor (const uintptr_t x) noexcept
 获取不大于x的最大2的幂
MSTL_CONSTEXPR14 uint64_t bit_ceil (const uintptr_t x) noexcept
 获取不小于x的最小2的幂
constexpr bool has_single_bit (const uintptr_t x) noexcept
 检查整数是否为2的幂
MSTL_CONSTEXPR14 uint32_t rotate_l32 (const uint32_t x, const int s) noexcept
 32位整数循环左移
MSTL_CONSTEXPR14 uint32_t rotate_r32 (const uint32_t x, const int s) noexcept
 32位整数循环右移
MSTL_CONSTEXPR14 int rotate_l (const uintptr_t x, const int s) noexcept
 整数循环左移
MSTL_CONSTEXPR14 int rotate_r (const uintptr_t x, const int s) noexcept
 整数循环右移
constexpr uintptr_t bit_extract (const uintptr_t x, const int pos, const int len) noexcept
 从整数中提取指定位段
MSTL_CONSTEXPR14 uintptr_t bit_insert (const uintptr_t x, const uintptr_t bits, const int pos, const int len) noexcept
 向整数中插入指定位段
MSTL_CONSTEXPR14 uint32_t reverse_bits32 (uint32_t x) noexcept
 反转32位整数的位顺序
constexpr uintptr_t reverse_bits (const uintptr_t x) noexcept
 反转整数的位顺序
constexpr uintptr_t mask_from_to (const int from, const int to) noexcept
 生成从from到to的位掩码

详细描述

位宽计算、位取整和位检查函数

函数说明

◆ bit_ceil()

MSTL_CONSTEXPR14 uint64_t bit_ceil ( const uintptr_t x)
noexcept

获取不小于x的最小2的幂

参数
x无符号整数
返回
不小于x的最小2的幂,如果x为0则返回1

在文件 bit.hpp295 行定义.

引用了 bit_floor() , 以及 floor().

◆ bit_extract()

uintptr_t bit_extract ( const uintptr_t x,
const int pos,
const int len )
constexprnoexcept

从整数中提取指定位段

参数
x源整数
pos起始位置,从0开始
len要提取的位数
返回
提取的位段

在文件 bit.hpp410 行定义.

◆ bit_floor()

uintptr_t bit_floor ( const uintptr_t x)
constexprnoexcept

获取不大于x的最大2的幂

参数
x无符号整数
返回
不大于x的最大2的幂,如果x为0则返回0

在文件 bit.hpp286 行定义.

引用了 bit_width().

被这些函数引用 bit_ceil().

◆ bit_insert()

MSTL_CONSTEXPR14 uintptr_t bit_insert ( const uintptr_t x,
const uintptr_t bits,
const int pos,
const int len )
noexcept

向整数中插入指定位段

参数
x目标整数
bits要插入的位段
pos插入位置,从0开始
len要插入的位数
返回
插入后的整数

在文件 bit.hpp422 行定义.

◆ bit_width()

int bit_width ( const uintptr_t x)
constexprnoexcept

计算表示整数所需的最小位宽

参数
x无符号整数
返回
表示x所需的最小位数

在文件 bit.hpp273 行定义.

引用了 countl_zero().

被这些函数引用 bit_floor().

◆ has_single_bit()

bool has_single_bit ( const uintptr_t x)
constexprnoexcept

检查整数是否为2的幂

参数
x无符号整数
返回
如果x是2的幂则返回true,否则返回false

在文件 bit.hpp306 行定义.

◆ mask_from_to()

uintptr_t mask_from_to ( const int from,
const int to )
constexprnoexcept

生成从from到to的位掩码

参数
from起始位置(包含)
to结束位置(包含)
返回
从from位到to位为1,其他位为0的掩码

在文件 bit.hpp483 行定义.

◆ reverse_bits()

uintptr_t reverse_bits ( const uintptr_t x)
constexprnoexcept

反转整数的位顺序

参数
x无符号整数
返回
位反转后的整数

根据平台位数调用相应的位反转函数。

在文件 bit.hpp468 行定义.

引用了 reverse_bits32().

◆ reverse_bits32()

MSTL_CONSTEXPR14 uint32_t reverse_bits32 ( uint32_t x)
noexcept

反转32位整数的位顺序

参数
x32位无符号整数
返回
位反转后的整数

在文件 bit.hpp433 行定义.

被这些函数引用 reverse_bits().

◆ rotate_l()

MSTL_CONSTEXPR14 int rotate_l ( const uintptr_t x,
const int s )
noexcept

整数循环左移

参数
x无符号整数
s旋转位数
返回
循环左移后的结果

根据平台位数调用相应的循环左移函数。

在文件 bit.hpp378 行定义.

引用了 rotate_l32().

◆ rotate_l32()

MSTL_CONSTEXPR14 uint32_t rotate_l32 ( const uint32_t x,
const int s )
noexcept

32位整数循环左移

参数
x32位无符号整数
s旋转位数
返回
循环左移后的结果

在文件 bit.hpp316 行定义.

被这些函数引用 rotate_l().

◆ rotate_r()

MSTL_CONSTEXPR14 int rotate_r ( const uintptr_t x,
const int s )
noexcept

整数循环右移

参数
x无符号整数
s旋转位数
返回
循环右移后的结果

根据平台位数调用相应的循环右移函数。

在文件 bit.hpp394 行定义.

引用了 rotate_r32().

◆ rotate_r32()

MSTL_CONSTEXPR14 uint32_t rotate_r32 ( const uint32_t x,
const int s )
noexcept

32位整数循环右移

参数
x32位无符号整数
s旋转位数
返回
循环右移后的结果

在文件 bit.hpp330 行定义.

被这些函数引用 rotate_r().