Skip to content

Instantly share code, notes, and snippets.

@lix19937
Created June 24, 2025 06:37
Show Gist options
  • Save lix19937/a012082b78b88d941de4ed7f02d03160 to your computer and use it in GitHub Desktop.
Save lix19937/a012082b78b88d941de4ed7f02d03160 to your computer and use it in GitHub Desktop.
ClearBit.cpp
#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