BIT(3) Library Functions Manual BIT(3)

KS_clamp, KS_u8_clamp, KS_u16_clamp, KS_u32_clamp, KS_extract_and_depositbit manipulation functions

#include <libks/bit.h>

KS_clamp(uint64_t x, int nbits);

uint8_t
KS_u8_clamp(uint64_t x);

uint16_t
KS_u16_clamp(uint64_t x);

uint32_t
KS_u32_clamp(uint64_t x);

uint64_t
KS_extract_and_deposit(uint64_t val, uint64_t extract_mask, uint64_t deposit_mask);

The () macro clamps x to nbits number of bits. Its return type will be proportional to an nbits wide integer.

The () function clamps x to an 8-bit integer.

The () function clamps x to an 16-bit integer.

The () function clamps x to an 32-bit integer.

The () function extracts the bits in val according to the extract_mask. The placement of the extracted bits in the return value is determined by the deposit_mask in which the first extracted bit will be placed at the first non-zero bit in deposit_mask and so forth.

Anton Lindqvist <anton@basename.se>

OpenBSD 7.8 July 2, 2025 BIT(3)