A n-bit unsigned integer is like a numbered bucket that can only hold certain numbers, and it's made up of n little switches that can be either on or off.
Imagine you have a bucket that holds marbles. Each marble represents a number, and the bucket has space for exactly 2^n marbles, meaning if your bucket is 3-bit, it can hold up to 8 marbles (because $2^3 = 8$). These buckets are super simple: they don’t have negative numbers or fancy features, just plain counting from 0 all the way up to 2^n - 1.
How It Works
Each switch in the bucket is like a light that can be on (1) or off (0). If you have 4 switches, you get a 4-bit unsigned integer, which can count up to 15 (because $2^4 = 16$, and we start from 0).
So if all the lights are off, that means 0. If only the first light is on, it’s 1. If all the lights are on, you get the biggest number, in this case, 15.
It's like having a 4-digit counter that only goes from 0 to 15, and each digit can only be 0 or 1, just like your fingers can be up or down!
Examples
- It's like having a counter with only 3 switches, each on or off.
- If you have 4 bits, you can go up to 15.
Ask a question
See also
- How Does a Computer (Physically) Read Code?
- What is 0s and 1s?
- What is Computers use binary because it's simple?
- Why Do We Use Binary in Computers?
- Why Are Some Numbers 'Favourite' to Computers?