![]() |
In C++ 20, the std::has_single_bit function is a predefined function that is used to check if a given value is an integral power of two or not. This function is defined in the <bit> header file. The std::has_single_bit() function works by checking whether a given integer has exactly one bit set to ‘1’ in its binary representation because the numbers that are powers of two have only one bit set in their binary form. For example, 2 is 10 in binary, 4 is 100, 8 is 1000 and so on. Syntax of std::has_single_bit() in C++std::has_single_bit(num) Parameters of has_single_bit()This function accepts a single parameter:
Return Value has_single_bit()The std::has_single_bit function return:
Example of std::has_single_bit in C++Input: The below example demonstrates how we can use has_single_bit() function to check if a given value is an integral power of two in C++.
16 has a single bit set. Time Complexity : O(1), function has_single_bit() is a constant-time operation
|
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 21 |