GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::bit_floor(3) C++ Standard Libary std::bit_floor(3)

std::bit_floor - std::bit_floor


Defined in header <bit>
template< class T > (since C++20)
constexpr T bit_floor( T x ) noexcept;


If x is not zero, calculates the largest integral power of two that is not greater
than x. If x is zero, returns zero.


This overload participates in overload resolution only if T is an unsigned integer
type (that is, unsigned char, unsigned short, unsigned int, unsigned long, unsigned
long long, or an extended unsigned integer type).


x - unsigned integer value


Zero if x is zero; otherwise, the largest integral power of two that is not greater
than x.


Feature-test macro: __cpp_lib_int_pow2


template <std::unsigned_integral T>
requires !std::same_as<T, bool> && !std::same_as<T, char> &&
!std::same_as<T, char8_t> && !std::same_as<T, char16_t> &&
!std::same_as<T, char32_t> && !std::same_as<T, wchar_t>
constexpr T bit_floor(T x) noexcept
{
if (x != 0)
return T{1} << (std::bit_width(x) - 1);
return 0;
}

// Run this code


#include <bit>
#include <bitset>
#include <iostream>


int main()
{
using bin = std::bitset<8>;


for (unsigned x = 0; x != 10; ++x)
{
auto const z = std::bit_floor(x); // `floor2` before P1956R1


std::cout << "bit_floor( " << bin(x) << " ) = " << bin(z) << '\n';
}
}


bit_floor( 00000000 ) = 00000000
bit_floor( 00000001 ) = 00000001
bit_floor( 00000010 ) = 00000010
bit_floor( 00000011 ) = 00000010
bit_floor( 00000100 ) = 00000100
bit_floor( 00000101 ) = 00000100
bit_floor( 00000110 ) = 00000100
bit_floor( 00000111 ) = 00000100
bit_floor( 00001000 ) = 00001000
bit_floor( 00001001 ) = 00001000


bit_ceil finds the smallest integral power of two not less than the given
(C++20) value
(function template)
rotr computes the result of bitwise right-rotation
(C++20) (function template)
bit_width finds the smallest number of bits needed to represent the given value
(C++20) (function template)
has_single_bit checks if a number is an integral power of two
(C++20) (function template)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.