Created
May 6, 2025 08:16
-
-
Save lix19937/2fc4588c9ff25b13b1cc07953e8dc148 to your computer and use it in GitHub Desktop.
setBit.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdint.h> | |
#include <iostream> | |
#include <bitset> | |
uint32_t setBit(uint32_t position) { | |
uint32_t num = 0; | |
num |= (1 << position); | |
return num; | |
} | |
int main() { | |
uint32_t a = setBit(0); | |
uint32_t a1 = setBit(3); | |
uint32_t a2 = setBit(8); | |
uint32_t a3 = setBit(9); | |
uint32_t a4 = setBit(10); | |
uint32_t a5 = setBit(11); | |
uint32_t b = a| a1|a2|a3|a4|a5; | |
std::cout << (std::bitset<12>)b << "," << b<< std::endl; | |
return 0; | |
} | |
// https://www.onlinegdb.com/online_c++_compiler | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment