STDC_BIT_FLOOR(3C) Standard C Library Functions STDC_BIT_FLOOR(3C)
stdc_bit_floor, stdc_bit_floor_uc, stdc_bit_floor_us,
stdc_bit_floor_ui, stdc_bit_floor_ul, stdc_bit_floor_ull - find largest
power of 2 smaller than value
Standard C Library (libc, -lc)
#include <stdbit.h>
generic_value_type
stdc_bit_floor(generic_value_type value);
unsigned char
stdc_bit_floor_uc(unsigned char value);
unsigned short
stdc_bit_floor_us(unsigned short value);
unsigned int
stdc_bit_floor_ui(unsigned int value);
unsigned long
stdc_bit_floor_ul(unsigned long value);
unsigned long long
stdc_bit_floor_ull(unsigned long long value);
The stdc_bit_floor() family of functions determine the largest power of
2 that is not greater than value. If value is 0, then the function
returns 0.
The stdc_bit_floor() function is generic and will operate on all 8, 16,
32, and 64-bit unsigned integers; however, it is only available in C23.
The other functions all operate on a specific integer type, but
otherwise behave the same and are available regardless of the C
language version.
The functions in the stdc_bit_floor() family returns the largest power
of 2 that is not greater than value. These functions cannot fail.
Example 1 Printing the bit floor of an integer.
#include <stdbit.h>
#include <stdio.h>
#include <limits.h>
int
main(void)
{
printf("0x%x 0x%x 0x%x 0x%llx\n",
stdc_bit_floor_uc(0x2b),
stdc_bit_floor_us(0x1000),
stdc_bit_floor_ui(UINT32_MAX),
stdc_bit_floor_ull(0));
return (0);
}
When compiled and run, this produces:
$ ./a.out
0x20 0x1000 0x80000000 0x0
Committed
MT-LEVEL
Async-Signal-Safe
stdc_bit_ceil(3C), stdc_bit_width(3C), stdc_count_ones(3C),
stdc_count_zero(3C), stdc_first_leading_one(3C),
stdc_first_leading_zero(3C), stdc_first_trailing_one(3C),
stdc_first_trailing_zero(3C), stdc_has_single_bit(3C),
stdc_leading_ones(3C), stdc_leading_zeros(3C), stdc_trailing_ones(3C),
stdc_trailing_zeros(3C), stdbit.h(3HEAD)
illumos October 27, 2024 illumos
NAME
stdc_bit_floor, stdc_bit_floor_uc, stdc_bit_floor_us,
stdc_bit_floor_ui, stdc_bit_floor_ul, stdc_bit_floor_ull - find largest
power of 2 smaller than value
LIBRARY
Standard C Library (libc, -lc)
SYNOPSIS
#include <stdbit.h>
generic_value_type
stdc_bit_floor(generic_value_type value);
unsigned char
stdc_bit_floor_uc(unsigned char value);
unsigned short
stdc_bit_floor_us(unsigned short value);
unsigned int
stdc_bit_floor_ui(unsigned int value);
unsigned long
stdc_bit_floor_ul(unsigned long value);
unsigned long long
stdc_bit_floor_ull(unsigned long long value);
DESCRIPTION
The stdc_bit_floor() family of functions determine the largest power of
2 that is not greater than value. If value is 0, then the function
returns 0.
The stdc_bit_floor() function is generic and will operate on all 8, 16,
32, and 64-bit unsigned integers; however, it is only available in C23.
The other functions all operate on a specific integer type, but
otherwise behave the same and are available regardless of the C
language version.
RETURN VALUES
The functions in the stdc_bit_floor() family returns the largest power
of 2 that is not greater than value. These functions cannot fail.
EXAMPLES
Example 1 Printing the bit floor of an integer.
#include <stdbit.h>
#include <stdio.h>
#include <limits.h>
int
main(void)
{
printf("0x%x 0x%x 0x%x 0x%llx\n",
stdc_bit_floor_uc(0x2b),
stdc_bit_floor_us(0x1000),
stdc_bit_floor_ui(UINT32_MAX),
stdc_bit_floor_ull(0));
return (0);
}
When compiled and run, this produces:
$ ./a.out
0x20 0x1000 0x80000000 0x0
INTERFACE STABILITY
Committed
MT-LEVEL
Async-Signal-Safe
SEE ALSO
stdc_bit_ceil(3C), stdc_bit_width(3C), stdc_count_ones(3C),
stdc_count_zero(3C), stdc_first_leading_one(3C),
stdc_first_leading_zero(3C), stdc_first_trailing_one(3C),
stdc_first_trailing_zero(3C), stdc_has_single_bit(3C),
stdc_leading_ones(3C), stdc_leading_zeros(3C), stdc_trailing_ones(3C),
stdc_trailing_zeros(3C), stdbit.h(3HEAD)
illumos October 27, 2024 illumos