<p>I'm trying to implement a data compression idea I've had, and since I'm imagining running it against a large corpus of test data, I had thought to code it in C (I mostly have experience in scripting languages like Ruby and Tcl.) </p>

<p>Looking through the O'Reilly 'cow' books on C, I realize that I can't simply index the bits of a simple 'char' or 'int' type variable as I'd like to to do bitwise comparisons and operators.  </p>

<p>Am I correct in this perception?   Is it reasonable for me to use an enumerated type for representing a bit (and make an array of these, and writing functions to convert to and from char)?  If so, is such a type and functions defined in a standard library already somewhere?  Are there other (better?) approaches?   Is there some example code somewhere that someone could point me to?</p>

<p>Thanks - </p>

It is possible.
To set the nth bit, use OR:
```
```
x |= (1 << 5); // sets the 5th-from right
```
```
To clear a bit, use AND:
```
```
x &= ~(1 << 5); // clears 5th-from-right
```
```
To flip a bit, use XOR:
```
```
x ^= (1 << 5); // flips 5th-from-right
```
```
To get the value of a bit use shift and AND:
```
```
(x & (1 << 5)) >> 5 // gets the value (0 or 1) of the 5th-from-right
```
```
note: the shift right 5 is to ensure the value is either 0 or 1. If you're just interested in 0/not 0, you can get by without the shift.