How can i change bits from a Binary Variable?

task 1. how can i change bit 1 to 0 and 0 to 1 for example From B10101010 to B01010101

task 2. how can i replace a bit with the something else? for example from B10001001 to B10000001 (change the 1 in the middle with 0)

is there any tutorial of some examples like these?

There are a number of bit manipulation functions - bitSet(), bitClear(), bitRead(), bitWrite(). See http://arduino.cc/en/Reference/HomePage.

To change all of the ones to zeros, and vice versa, in a single byte, exclusive-or it with all ones:

byte b = 0xaa;

b = b ^ 0xff;

Regards,

-Mike