TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Implementation to [From the right, set the Kth bit in the binary representation of N] (https://practice.geeksforgeeks.org/problems/set-kth-bit3724/1/) in an integer. More...
#include <cassert>
#include <cstdint>
#include <iostream>
Go to the source code of this file.
Namespaces | |
namespace | bit_manipulation |
for assert | |
namespace | setKthBit |
Functions for the [From the right, set the Kth bit in the binary representation of N] (https://practice.geeksforgeeks.org/problems/set-kth-bit3724/1/) implementation. | |
Functions | |
std::uint64_t | bit_manipulation::set_kth_bit::setKthBit (std ::int64_t N, std ::int64_t k) |
The main function implements set kth bit. | |
static void | test () |
Self-test implementations. | |
int | main () |
Main function. | |
Implementation to [From the right, set the Kth bit in the binary representation of N] (https://practice.geeksforgeeks.org/problems/set-kth-bit3724/1/) in an integer.
Given a number N and a value K. From the right, set the Kth bit in the binary representation of N. The position of Least Significant Bit(or last bit) is 0, the second last bit is 1 and so on. in it.
A binary number consists of two digits. They are 0 & 1. Digit 1 is known as set bit in computer terms. Worst Case Time Complexity: O(1) Space complexity: O(1)
Definition in file set_kth_bit.cpp.
int main | ( | void | ) |
Main function.
Definition at line 77 of file set_kth_bit.cpp.
std::uint64_t bit_manipulation::set_kth_bit::setKthBit | ( | std ::int64_t | N, |
std ::int64_t | k ) |
The main function implements set kth bit.
N | is the number whose kth bit will be set |
Definition at line 43 of file set_kth_bit.cpp.
|
static |
Self-test implementations.
Definition at line 61 of file set_kth_bit.cpp.