Question: I have this table:

```
// numbers
+---------+------------+
|    id   |    numb    |
+---------+------------+
| int(11) |   bit(10)  |
+---------+------------+
| 1       | 1001100111 |
| 2       | 0111000101 |
| 3       | 0001101010 |
| 4       | 1111111011 |
+---------+------------+

```

I'm trying to change *(toggle)* the value of seventh digit *(right to left)*. So focus on this digit:

```
// for example
1001100111
  ^ seventh digit (rtl)

```

And this is expected result:

```
// new_numbers
+---------+------------+
|    id   |    numb    |
+---------+------------+
| int(11) |   bit(10)  |
+---------+------------+
| 1       | 10**1**1100111 |
| 2       | 01**0**1000101 |
| 3       | 00**1**1101010 |
| 4       | 11**0**1111011 |
+---------+------------+

```

---

I can update seventh digit like

```
// set it to zero
UPDATE numbers SET numb = numb & b'1110111111';

```

But actually I need to toggle it.

* if it is `0` then set it `1`
* if it is `1` then set it `0`

How can I do that?

Answer: 
Flipping a bit is done by XOR `^` operation with a mask that has `1`s in positions that you would like to toggle.

This works because the truth table of XOR looks like this:

```
  A: 0 0 1 1
  B: 0 1 0 1
A^B: 0 1 1 0

```

Note the columns where `B` is `1`: when the corresponding bit in `A` is zero, the result is one, and vice versa.

Togging seventh bit is done like this:

```
UPDATE numbers SET numb = numb ^ b'0001000000';

```
You can it easy do with XOR ^ . you can give the operand in any system like 1,2,4,8..., for bit 0,1,2,3 OR b'1', b'10', b'100'. Each bit is set was inverted.

In you Sample is the operand 128 or b'100000000'

**SAMPLE**

```
SELECT  b'1110111110' ^ 1 , b'1110111111' ^ 1 ;
SELECT  b'1110111110' ^ 128 , b'1100111111' ^ 128 ;

```

**If you want to see it as BITs**

```
SELECT  BIN( b'1110111110' ^ 1   ), BIN( b'1110111111' ^ 1   );
SELECT  BIN( b'1110111110' ^ 128 ), BIN( b'1100111111' ^ 128 );

```