Deep C Dives: All You Need Are Bits
Written by Mike James   
Wednesday, 21 January 2026
Article Index
Deep C Dives: All You Need Are Bits
Specifying Bit Patterns
Zero

If there is a single characteristic that sets C programmers apart, it is an understanding of bits. If you don’t understand bits then you are a programmer in some other language pretending to be a C programmer. Harsh, but true. Find out why the bit has an important role to play in this extract from my book, Deep C Dives.

Deep C Dives
Adventures in C

By Mike James

Cdive360

Buy from Amazon.

Contents

Preface
Prolog C
Dive

  1. All You Need Are Bits
    Extract
    All You Need Are Bits ***NEW!
  2. These aren’t the types you’re looking for
  3. Type Casting
  4. Expressions
  5. Bits and More Bits
        Extract:
    Bits!
  6. The Brilliant But Evil for 
  7. Into the Void 
  8. Blocks, Stacks and Locals
  9. Static Storage
  10. Pointers
  11. The Array and Pointer Arithmetic
  12. Heap, The Third Memory Allocation
  13. First Class Functions
        Extract:
    First Class Functions
  14. Structs and Objects
        ExtractValue Structs 
  15. The Union
  16. Undefined Behavior
  17. Exceptions and the Long Jump

<ASIN:B0D6LZZQ8R>

Dive 1

All You Need Are Bits

Bits are the raw material out of which we fashion the world.”

Most accounts of bit patterns start off from binary values then move on to two’s complement and finally, sometimes floating-point, but this simply hides the fact that bits aren’t any of these things. Let’s start at the beginning.

States

A bit is a two-state system – a bit can be a 1 or a 0. It doesn’t matter what you call these two states, true and false will do, but so will up and down or on and off and many more. Computers work in terms of groups of bits which can be accessed and worked with as a single unit. Typically the size of the group is eight bits, that is a byte. While this isn’t strictly necessary, we’ll use it in our examples which would be similar for a different number of bits.

The eight bits in a byte are usually have a particular order and are generally numbered starting from the right:

7 6 5 4 3 2 1 0
x x x x x x x x

Bit 0 is generally called the “lowest” or “least significant bit” and bit 7 is called the “highest” or “most significant bit”. The reason for this terminology comes from regarding the group of bits as a binary number. Notice that we need to make an “endian” decision. Which end to number bits from is arbitrary and depends on the machine’s architecture, but this big-endian numbering is almost universal. The reason for this will become apparent when we deal with place value systems later.

Any bit in a byte can represent one of two states. For example, you could represent the state of a set of eight lights one per bit position corresponding to on and off. Storing a bit pattern into the byte would set the lights to a particular state and reading the bit pattern would give the state of the lights – notice no numbers were involved in this transaction.

Consider now what happens if a room has two lights in it, a left and a right. Now we have four possible states:

left light off right light off      0 0
left light off right light on       0 1
left light on  right light off      1 0
left light on  right light on       1 1

So, if you have four states to represent, we need to use two bits, eight states need three bits, 16 states four bits and so on. If you have a number of states that doesn’t fit exactly into n bits then you simply combine some of the extra states. For example:

no  lights on    0 0
one light  on    0 1 or 1 0
two lights on    1 1

is how you might represent three states using two bits, but there are alternatives.

Again no numbers are involved in this – only bits.



Last Updated ( Wednesday, 21 January 2026 )