A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://TheAlgorithms.github.io/C-Plus-Plus/d5/db5/set__kth__bit_8cpp_source.html below:

TheAlgorithms/C++: bit_manipulation/set_kth_bit.cpp Source File

Go to the documentation of this file. 37namespace

set_kth_bit {

44

std ::int64_t k) {

// int64_t is preferred over int so 45 // that no Overflow can be there. 48

1 << k;

// "pos" variable is used to store 1 at kth postion and 49 // rest bits are 0. in binary representation of number 'n' 51 return

N | pos;

// by taking or with the pos and the N we set the bit of N 54

}

// namespace set_kth_bit 55

}

// namespace bit_manipulation 66 // n = 400001,5 return 400033 71

std::cout <<

"All test cases successfully passed!"

<< std::endl;

78 test

();

// run self-test implementations

Functions for the [From the right, set the Kth bit in the binary representation of N] (https://practi...

static void test()

Self-test implementations.

std::uint64_t setKthBit(std ::int64_t N, std ::int64_t k)

The main function implements set kth bit.

int main()

Main function.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4