> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/man/misc/stdbit.3.md).

# stdbit.3

`stdbit` — 位与字节实用工具

## 名称

`stdbit`

## 概要

`Lb libc`

```c
#include <stdbit.h>
```

```c
#define __STDC_ENDIAN_LITTLE__
#define __STDC_ENDIAN_BIG__
#define __STDC_ENDIAN_NATIVE__

unsigned int stdc_count_leading_zeros(value);
unsigned int stdc_count_leading_ones(value);
unsigned int stdc_count_trailing_zeros(value);
unsigned int stdc_count_trailing_ones(value);
unsigned int stdc_first_leading_zero(value);
unsigned int stdc_first_leading_one(value);
unsigned int stdc_first_trailing_zero(value);
unsigned int stdc_first_trailing_one(value);
unsigned int stdc_count_zeros(value);
unsigned int stdc_count_ones(value);
bool stdc_has_single_bit(value);
unsigned int stdc_bit_width(value);
typeof(value) stdc_bit_floor(value);
typeof(value) stdc_bit_ceil(value);
```

## 描述

`__STDC_ENDIAN_NATIVE__` 宏描述了构建程序所针对的机器的字节序或端序。如果机器具有大端字节序，此宏等于 `__STDC_ENDIAN_BIG__`。如果机器具有小端字节序，此宏等于 `__STDC_ENDIAN_LITTLE__`。否则，该宏具有不等于两者的值。

位与字节实用函数分析数据内的位。每个函数 *func* 以五种变体提供：`stdc_`*func*`_`*type*(*value*)，其中 `value` 的类型分别为 `unsigned char`、`unsigned short`、`unsigned int`、`unsigned long` 或 `unsigned long long`，对应 *type* 为 **uc**、**us**、**ui**、**ul** 或 **ull**。此外，对于每个 *func*，提供一个类型通用宏 `stdc_`*func*(*value*)，根据 `value` 的类型选择适当的函数 `stdc_`*func*`_`*type*(*value*)。

## 参见

[arch(7)](/man/man7/arch.7.md), [bitstring(3)](/man/misc/bitstring.3.md), ffs(3), fls(3), stdc\_count\_leading\_zeros(3), stdc\_count\_leading\_ones(3), stdc\_count\_trailing\_zeros(3), stdc\_count\_trailing\_ones(3), stdc\_first\_leading\_zero(3), stdc\_first\_leading\_one(3), stdc\_first\_trailing\_zero(3), stdc\_first\_trailing\_one(3), stdc\_count\_zeros(3), stdc\_count\_ones(3), stdc\_has\_single\_bit(3), stdc\_bit\_width(3), stdc\_bit\_floor(3), stdc\_bit\_ceil(3)

## 标准

```c
#include <stdbit.h>
```

头文件中的宏和函数遵循 -isoC-2023 标准。

## 历史

```c
#include <stdbit.h>
```

头文件及其定义的宏和函数在 FreeBSD 15.1 中添加。

## 作者

Robert Clausecker <fuz@FreeBSD.org>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://book.bsdcn.org/man/misc/stdbit.3.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
