Reading 2: Bits and Integers

There are 10 kinds of people in the world...

8 Bits: A Very Common Building Block

In digital systems, bits are rarely used one at a time. Instead, they are grouped into convenient units. The most common grouping is the byte:

1 byte = 8 bits

Because each bit can be 0 or 1, the total number of possible patterns is:

2 × 2 × 2 × 2 × 2 × 2 × 2 × 2 = 28 = 256 patterns

When we use 8 bits to represent unsigned integers (only zero and positive numbers. No negative numbers.), each unique pattern of bits corresponds to a different number. If we start counting at 0, those 256 patterns represent the integers from 0 to 255. This 0–255 range appears all over computing: pixel values, color channels, and simple data types in many programming languages. 

Obviously computers need to store both positive and negative numbers. For simplicity as we get started, the following conversation will only deal with "unsigned" integers.

Binary Place Value for 8‑Bit Integers

You and your students are already familiar with decimal (base 10) place values: ones, tens, hundreds, and so on. Each place is 10 times the value of the place to its right.

Position 3 2 1 0
Place value 1000 100 10 1

If we wanted to represent 154, we would know that we need 1 group of 100, five groups of 10, and 4 groups of 1.

10³
10²
10¹
10⁰
1000
100
10
1
0
1
5
4

154 can be written as 1×100 + 5×10 + 4×1

Binary (base 2) uses the same idea of place value, but the pattern is built from powers of 2 instead of powers of 10. Each place is worth twice the value of the place to its right.

For an 8‑bit binary number, the place values from left to right are:

Bit position 7 6 5 4 3 2 1 0
Power of 2 27 26 25 24 23 22 21 20
Place value 128 64 32 16 8 4 2 1
Notice the pattern here. In a binary system — where there are two values — each place value is double (or ×2) the place value to its right. This pattern is identical to the one we have in decimal systems where there are ten values. In that system each place value is ×10 the place value to its right. In fact, this pattern will hold in every number system. Each place value is ×N the place value to its right where N is the number of unique values in that number system.

When a bit is 1, we "include" that place value in our total. When it is 0, we do not.

If you can only have 1 or 0 of a particular place value, it takes a bit more information to encode a number in binary than it does in decimal. To represent 154 we would need 1 group of 128, 1 group of 16, 1 group of 8, and 1 group of 2 (since 154 = 128 + 16 + 8 + 2). Encoded in binary, this looks like:

2⁷
2⁶
2⁵
2⁴
2⁰
128
64
32
16
8
4
2
1
1
0
0
1
1
0
1
0

Converting Binary to Decimal

To convert an 8‑bit binary number to decimal, we multiply each bit by its place value and add the results.

Example: What number is 01010110?

Before reading the solution, try working this out yourself using the place value table above.

Consider this 8-bit binary number:

01010110

Match each 1 with its place value:

Add the non‑zero terms:

64 + 16 + 4 + 2 = 86

So 01010110 in binary represents the decimal number 86.

Converting Decimal to 8-Bit Binary

To convert from decimal to binary, one teacher-friendly method is the "place value subtraction" approach. The idea is simple: work through the binary place values from largest to smallest, asking at each step "does this place value fit into what I have left?" If yes, write a 1 and subtract. If no, write a 0 and move on.

Worked Example: Convert 156 to 8-bit binary

We will work through each of the 8 bit positions from left to right, starting with the largest place value (128) and ending with the smallest (1). At each step we ask: does this place value fit into our remaining amount?

Place value Remaining Does it fit? Bit New remaining
128156Yes (156 ≥ 128)1156 − 128 = 28
6428No (28 < 64)028
3228No (28 < 32)028
1628Yes (28 ≥ 16)128 − 16 = 12
812Yes (12 ≥ 8)112 − 8 = 4
44Yes (4 ≥ 4)14 − 4 = 0
20No (0 < 2)00
10No (0 < 1)00

Reading the bits from top to bottom gives us:

10011100

So 156 in decimal is 10011100 in 8-bit binary.

We can verify: 128 + 16 + 8 + 4 = 156. ✓

There are other methods (such as repeated division by 2), but this place-value approach is often easier to connect to students' existing understanding of decimal place value.

Now You Try: Convert 105 to 8-bit binary

Use the same place-value subtraction method. Work through each bit position from 128 down to 1, asking at each step whether the place value fits into your remaining amount. Write down your answer before expanding the solution below.

Show Answer
Place value Remaining Does it fit? Bit New remaining
128105No (105 < 128)0105
64105Yes (105 ≥ 64)1105 − 64 = 41
3241Yes (41 ≥ 32)141 − 32 = 9
169No (9 < 16)09
89Yes (9 ≥ 8)19 − 8 = 1
41No (1 < 4)01
21No (1 < 2)01
11Yes (1 ≥ 1)11 − 1 = 0

Reading the bits from top to bottom gives us:

01101001

So 105 in decimal is 01101001 in 8-bit binary.

We can verify: 64 + 32 + 8 + 1 = 105. ✓

Why the 0–255 Range Matters

Because 8 bits can represent 256 different patterns, a single byte can store integers from 0 to 255 when used as an unsigned value. This simple fact shows up in many real‑world contexts: