# pack\_bits()

指定したビット位置に1をセットします。

```cpp
constexpr uint32_t pack_bits(...)
```

パラメータは可変数引数で指定でき、各パラメータはビット位置を指定する0..31の整数を指定する。例えば`pack_bits(1,3,6)`と指定すると`((1UL<<1)|(1UL<<3)|(1UL<<6))`を返します。

{% hint style="info" %}
`constexpr`は定数による計算が可能な場合はコンパイル時に定数展開します。
{% endhint %}

## 背景

IOポート(DI,DO)の状態など各種ビットマップに値を参照・設定する場面があり、その記述を簡素化するため。


---

# Agent Instructions: 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:

```
GET https://mwx.twelite.info/api-reference/funcs/utility/pack_bits.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
