Created
June 24, 2025 06:37
-
-
Save lix19937/a012082b78b88d941de4ed7f02d03160 to your computer and use it in GitHub Desktop.
ClearBit.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 <iostream> | |
#include <stdint.h> | |
#include <bitset> | |
uint32_t SetBit(uint32_t position) { | |
uint32_t num = 0; | |
num |= (1 << position); | |
return num; | |
} | |
uint32_t ClearBit(uint32_t num, uint32_t position) { | |
return num & ~(1U << position); | |
} | |
int main() | |
{ | |
std::cout<<"Hello World\n"; | |
uint32_t value = 0xFF; | |
value = ClearBit(value, 3); | |
std::cout<<"Hello World: " << value; | |
std::cout << "\n"<< std::bitset<8>(value) << std::endl; // 32d= | |
value = ClearBit(value, 1); | |
std::cout << "\n"<< std::bitset<8>(value) << std::endl; // 32d= | |
value = ClearBit(value, 0); | |
std::cout << "\n"<< std::bitset<8>(value) << std::endl; // 32d= | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment