TL;DR / Summary: Memory sizing problems reduce to identifying bit widths, byte counts, and repeated doublings. These worked examples walk through RAM modules, array footprints, and address calculations using 2^n. Double-check arithmetic with our free power of 2 calculator.
Example 1: unsigned byte range
Question: How many distinct values can an 8-bit unsigned integer store?
Solution: 2^8 = 256 values, typically 0 through 255 inclusive. Off-by-one errors treat 255 as count—remember inclusive range size formula: max – min + 1 = 256.
Example 2: array memory footprint
Question: A float32 array holds 4096 elements. How many bytes?
Solution: Each float32 = 4 bytes = 2^2 bytes. Total = 4096 × 4 = 16384 bytes. Recognize 4096 = 2^12, so total = 2^12 × 2^2 = 2^14 = 16384 bytes = 16 KiB.
Example 3: pointer addressing
Question: Thirty-two-bit pointers address how many bytes directly?
Solution: 2^32 bytes = 4 GiB. If each struct is 64 bytes = 2^6, maximum struct count ≈ 2^32 / 2^6 = 2^26 ≈ 67 million structs before virtual memory limits intervene.
Example 4: alignment padding
Question: Struct size 100 bytes packed in 64-byte cache lines. How much waste for 10,000 structs naive layout?
Solution: Objects span ceil(100/64) = 2 lines each → 128 bytes allocated per object for alignment worst case. Overhead 28 bytes × 10000. Power-of-two line size 64 = 2^6 simplifies bitmask alignment: address & 63 must be zero for line start.
Example 5: bitmap allocation
Question: Track 65536 slots with one bit each. Bitmap size?
Solution: 65536 bits / 8 = 8192 bytes = 2^13 bytes. Slots = 2^16, bytes = 2^16 / 2^3 = 2^13.
Example 6: doubling heap growth
Question: Dynamic array starts 16 elements, doubles when full. After how many doublings capacity reaches at least 10000?
Solution: Capacities: 16=2^4, then 32, 64, … find smallest k where 2^(4+k) ≥ 10000. 2^13 = 8192 insufficient; 2^14 = 16384 sufficient. k = 10 doublings from start? Track: n=0→16, after 10 doublings 16×2^10 = 16384. Ten resize events.
Example 7: VRAM texture budget
Question: One 2048×2048 RGBA8 texture—memory?
Solution: 2048 = 2^11. Pixels = 2^11 × 2^11 = 2^22. Bytes per pixel = 4 = 2^2. Total = 2^24 = 16 MiB per mip level base. Full mip chain ≈ 4/3 × base—still power-of-two dominated.
Verification habit
After manual exponent algebra, plug intermediate 2^n values into trusted tools. Calculate 2 to the power of N online when chaining divides risks exponent subtraction mistakes.
Study workflow
Cover solution steps, attempt independently, reveal, compare exponent path versus decimal multiplication path. Both should match—if not, find whether bit/byte conflation caused drift.
Example 8: stack versus heap allocation
Question: Thread stack size default 8 MiB on many Linux systems—how many 2^10-byte pages?
Solution: 8 MiB = 8 × 2^20 bytes. Pages 4096 = 2^12 bytes. Count = 8 × 2^20 / 2^12 = 8 × 2^8 = 8 × 256 = 2048 pages per thread. Spawning 100 threads consumes roughly 800 MiB stack virtual address space before guard pages—capacity planning uses these 2^n steps.
Example 9: database page size
Question: SQLite default page 4096 bytes; database file 100 MB decimal approximate—how many pages order-of-magnitude?
Solution: 100 × 10^6 / 4096 ≈ 24414 pages. Exact power-of-two path: 4096 = 2^12. Decimal bytes not power-of-two—shows hybrid real-world problems mixing 10^n file labels with 2^n page sizes.
Peer review exercise
Swap worked examples with classmates; each finds one arithmetic step to challenge. Defending exponent subtraction in public solidifies learning faster than solitary rereading—especially on divide problems like bitmap sizing.
Example 10: video frame buffer
Question: 1920 by 1080 RGBA frame—bytes per frame?
Solution: Pixels equal 1920 times 1080—not power-of-two dimensions, because real content often is not. Bytes equal 1920 times 1080 times 4, which is 8,294,400 or about 7.91 MiB. Double-buffering for vsync doubles to roughly 15.8 MiB. Lesson: multiply actual dimensions; powers of two appear in bytes-per-pixel (4 equals 2^2) and MiB conversion (divide by 2^20), not always width and height.
Compare to 1024 by 1024 RGBA equals 2^20 times 4, which is 4 MiB exactly—idealized textbook case versus broadcast resolution homework.
Homework submission tips
Show exponent subtraction when dividing sizes— graders award partial credit for correct method with arithmetic slip. Box final answer with units: bytes, KiB, or bits explicitly.
Include sanity check line: result must be divisible by 4 when counting float32 elements— catches forgotten times four step early.
Whiteboard interview tip
When interviewer asks buffer size, narrate exponent steps aloud while writing—communication score often equals arithmetic score. Saying two to the twelfth bytes sounds professional versus mumbling four thousand ninety-six.
Finish with this habit: powers of 2 in Computer Memory
Memory worked examples combine 2^n bit counts, byte scaling, and real allocation patterns from arrays to GPU textures. Express sizes as exponents to multiply and divide by adding/subtracting powers. Practice until 2^12, 2^16, and 2^20 feel as familiar as decimal thousands.


