Changing a bit?

Hi may be it's easy but I can't find a solution how to change only one bit from a digit.
example: 181 = 10110101 wish to find and change the fifth posision(1) into zero(or one).so 165 = 10100101.

I have three variables: Digit,Position_in_digit, Value_of_position (0 or 1).

I can find a bit in the digit but how can I change it and restore the rest of bits?

Thank u.
digit|=1<<position_in_digit;
sets the bit
digit^=1<<position_in_digit;
unsets the bit.
You need to learn about the bitwise logical operators.
See here:
http://www.somacon.com/p125.php
Last edited on
Topic archived. No new replies allowed.