5.1.2 · D1C Programming

Foundations — Data types — char, short, int, long, float, double, size_t

1,879 words9 min readBack to topic

Before you can understand char, int, float, or size_t on the parent note, you need a small toolbox of ideas. This page builds every single one from nothing — no symbol used before it is drawn.


1. The bit — one switch

The picture: a single lightbulb. Dark = 0, lit = 1. That is the entire alphabet of a computer — just two symbols.

Why the topic needs it: every type (char, int, double) is measured in bits and bytes. If "bit" is fuzzy, "8 bits" and "how many patterns fit" stay fuzzy too.


2. The byte — a row of 8 switches, and counting patterns

Now the key question the whole topic leans on: how many different arrangements can 8 switches make?

The picture: a branching tree — one fork per bit. Count the leaves at the bottom: exactly of them for bits.

Why the topic needs it: the range of every integer type is derived straight from this count. No , no ranges.


3. The exponent notation

The picture: the same branching tree — is simply how many rows of forks you drew.

Why the topic needs it: ranges like and are written with exponents. You must read as "one row of forks fewer than ", i.e. half as many patterns.


4. Interval notation

The picture: a number line with a solid dot on , a solid dot on , and the whole stretch between them coloured in.

Why the topic needs it: every range in the parent — signed char , unsigned char — is written this way. If you misread the bracket you miscount by one at each end (the classic off-by-one bug).


5. Signed vs unsigned — where the minus sign hides

Here the same 256 patterns get two different meanings. This is the heart of the parent's integer section.

Unsigned: we agree every pattern names a non-negative count. Pattern 00000000 = 0, up to 11111111 = 255. Zero eats one slot, so the top value is , one less than the count.

Signed (two's complement): we sacrifice the top bit's usual meaning and give it a negative weight, so patterns starting with 1 name negatives.

The picture: a ring (odometer) of the 256 byte patterns. On the unsigned ring the labels run 0…255. On the signed ring the top half is relabelled to negatives: after 127 it flips to −128 and climbs back to −1. Same switches, different labels.

This is the two's-complement idea explored fully in Two's Complement Representation, and the wrap-around at the ring's seam is Integer Overflow and Undefined Behaviour.

Why the topic needs it: the parent's worked example (char c = 200 becoming -56) is exactly walking from the unsigned label to the signed label of the same pattern.


6. Scientific notation — the seed of float

Integers count in equal steps. But to store both an atom's size and a galaxy's size, you can't step evenly — you'd need billions of bits. Instead you store the number the way scientists write it.

The picture: a slider. The digits fix the shape of the number; the exponent slides the decimal point left (small) or right (huge). A few digits + a wide slider covers an enormous range.

Why the topic needs it: IEEE-754 float/double are binary scientific notation — a sign, a mantissa (the digits), and an exponent (the scale). This is the whole of IEEE-754 Floating Point.


7. The pieces of a float's formula

The parent writes . Every symbol, plainly:

Why the topic needs it: you cannot read "23 mantissa bits → ~7 digits" without knowing which part is the mantissa.


8. The sizeof question and size_t

The picture: a ruler that only reads upward (no negative marks) and is long enough to measure the biggest array the machine could ever hold.

Why the topic needs it: the parent's countdown-loop bug (size_t i; i >= 0) only makes sense once you know size_t is unsigned — its odometer can never dip below 0, so it wraps to a giant number instead.


How it all feeds the topic

bit = one switch 0 or 1

byte = 8 bits

pattern count = 2 to the n

exponent notation 2 to the n

interval a to b

signed vs unsigned labels

integer ranges char short int long

scientific notation

float and double formula

sizeof and size_t

Data types topic


Equipment checklist

Cover the right side and test yourself. You are ready when every line is instant.

What is a bit, in one phrase?
One switch that is either 0 (off) or 1 (on).
How many bits in a byte?
8.
Why do bit patterns multiply to and not add?
Each bit's choice is independent, so choices multiply: ( times).
How many patterns in bits?
.
What does equal, and why?
— multiplying by 2 zero times leaves the starting value 1.
What does the interval include?
Every whole number from to , including both ends.
Same 8 switches: unsigned top value vs signed top value?
Unsigned reaches 255; signed reaches 127.
Why is the signed range lopsided toward negatives?
Zero sits on the non-negative side, using a slot, leaving one fewer positive than negative.
In , what does give?
(a negative number).
What does the little in mean and why isn't it stored?
The always-present leading binary 1 (normalization) — implicit, so it's a free extra bit.
Why subtract a bias from the stored exponent ?
So a stored unsigned can still represent negative real exponents (tiny numbers).
What does sizeof return and in what units?
The size of a type/object, in bytes.
Why must size_t be unsigned?
A size (byte count) is never negative and must scale with addressable memory.