I want to know how to change a specific bit to 0/1 in C/C++.
c++ c bit-mamipulation
Use the bitwise OR operator (|).
number |= << x;
sets the x-th bit to 1.
Use the bitwise AND operator (&).
number &= ~(1<<x);
sets the x-th bit to zero
Use the XOR operator ().
number ^= 1 << x;
replaces the x-th bit with 0 if it is 1, and changes to 1 if it is 0.
Use the bitwise AND operator (&).
(number >> x ) & 1;
returns 1 if the x-th bit is 1, and 0 if 0 is 0.
© 2024 OneMinuteCode. All rights reserved.