Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

in built function to find MSB in cpp

// CPP program to find MSB
// number for given n.
#include <bits/stdc++.h>
using namespace std;
 
int setBitNumber(int n)
{
 
    // To find the position
    // of the most significant
    // set bit
    int k = (int)(log2(n));
 
    // To return the the value
    // of the number with set
    // bit at k-th position
    return 1 << k;
}
 
// Driver code
int main()
{
    int n = 273;
    cout << setBitNumber(n);
    return 0;
}
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #built #function #find #MSB #cpp
ADD COMMENT
Topic
Name
7+3 =