---
tags:
- linux
- l1
- flashcard-deck
- binary
---
<!-- wiki:breadcrumb:start -->
[Portal](../../../../library/portal/index.md) | **Level:** [L1: Foundations](../../../../library/portal/levels.md) | **Topics:** [Binary & Number Representation](../../../../library/portal/topics.md) | **Domain:** Linux
<!-- wiki:breadcrumb:end -->

id	category	difficulty	tags	question	answer	source_path
binary/a1d2e3f4b5c6	binary	easy	binary,bytes,interpretation	What determines the meaning of a byte sequence?	Context and interpretation. The same bits can represent an integer, text character, float component, machine instruction, or color value depending on how they are read.\n\nExample: the byte 0x41 is 'A' in ASCII, 65 as unsigned int, or part of a float — context decides.\n\nRemember: 'Same bits, different glasses.' The interpretation layer (text codec, int type, instruction set) gives bytes meaning.\n\nFun fact: this is why file format headers (magic bytes) exist — they tell programs how to interpret the rest of the bytes.	zines/how.integers.and.floats.work.wizard.zines.cleaned.notes
binary/b2e3f4a5c6d7	binary	easy	binary,integers,signed-unsigned	What is the range of an unsigned 8-bit integer?	0 to 255 (2^8 - 1).\n\nRemember: 2^8 = 256 values. Unsigned range: 0 to 255. Think 'an unsigned byte can count from zero to FF.'\n\nExample: RGB color channels are unsigned 8-bit: each of R, G, B ranges 0-255, giving 16.7 million colors total (256^3).\n\nFun fact: 255 = 0xFF = 11111111 in binary. All bits set = maximum value for any unsigned integer width.	zines/how.integers.and.floats.work.wizard.zines.cleaned.notes
binary/c3f4a5b6d7e8	binary	easy	binary,integers,signed-unsigned	What is the range of a signed 8-bit integer using two's complement?	-128 to 127. In two's complement, the most significant bit represents -(2^7) = -128, and the remaining 7 bits represent values up to 127 (0111 1111). This gives 256 distinct values: -128 through 0 through 127.\n\nRemember: signed range = -2^(n-1) to 2^(n-1)-1. For 8 bits: -128 to 127. The top bit 'costs' you half the positive range.\n\nGotcha: -128 has no positive counterpart in 8-bit two's complement. abs(-128) overflows back to -128!	zines/how.integers.and.floats.work.wizard.zines.cleaned.notes
binary/d4a5b6c7e8f9	binary	medium	binary,twos-complement,integers	What is two's complement and why is it used?	A representation for signed integers where negative numbers are encoded so that addition works correctly at the hardware level without special cases. The CPU uses the same circuitry for both signed and unsigned addition.\n\nRemember: to negate in two's complement: flip all bits, add 1. Example: 5 = 00000101, flip = 11111010, +1 = 11111011 = -5.\n\nUnder the hood: the CPU's adder circuit works identically for signed and unsigned — that's why two's complement won.	zines/how.integers.and.floats.work.wizard.zines.cleaned.notes
binary/e5b6c7d8f9a0	binary	medium	binary,overflow,integers	What happens when a fixed-width unsigned integer overflows?	It wraps around. For example, an 8-bit unsigned integer at 255 wraps to 0 when incremented. The behavior varies by language — some wrap silently, others trap or raise an error.\n\nRemember: 'Overflow = odometer rollover.' 255 + 1 = 0 for unsigned 8-bit, just like 999999 + 1 = 000000 on a car odometer.\n\nGotcha: in C, unsigned overflow is defined (wraps). Signed overflow is undefined behavior — the compiler can do anything.	zines/how.integers.and.floats.work.wizard.zines.cleaned.notes
binary/f6c7d8e9a0b1	binary	medium	binary,endianness,byte-order	What is endianness and why does byte order matter?	The byte order used to store multi-byte values in memory.\nLittle endian: least significant byte first.\nBig endian: most significant byte first.\nNetwork byte order is big endian.\n\nRemember: 'Big-endian = big end first' (MSB at lowest address). Network byte order is always big-endian (RFC 791).\n\nFun fact: the terms come from Gulliver's Travels — the Lilliputians fought over which end of an egg to crack first.\n\nExample: 0x12345678 in big-endian memory: [12][34][56][78]. Little-endian: [78][56][34][12].	zines/how.integers.and.floats.work.wizard.zines.cleaned.notes
binary/a7d8e9f0b1c2	binary	easy	binary,hexadecimal,notation	Why is hexadecimal useful for representing binary data?	Each hex digit maps to exactly 4 bits, so byte values align neatly (one byte = two hex digits). This makes hex dumps much more readable than decimal or raw binary.\n\nRemember: 1 hex digit = 4 bits = 1 nibble. 2 hex digits = 1 byte. So 0xFF = 1111 1111 = 255.\n\nExample: MAC addresses (aa:bb:cc:dd:ee:ff), IPv6, memory addresses, and color codes (#FF0000) all use hex.	zines/how.integers.and.floats.work.wizard.zines.cleaned.notes
binary/b8e9f0a1c2d3	binary	medium	binary,floats,precision	Why does 0.1 + 0.2 produce unexpected results in many languages?	Because 0.1 and 0.2 cannot be represented exactly in binary floating point. The stored approximations accumulate small rounding errors.\n\nExample: in Python, 0.1 + 0.2 == 0.30000000000000004. Use decimal.Decimal('0.1') + decimal.Decimal('0.2') for exact results.\n\nRemember: 'If it's money, don't use float.' Use integer cents or a Decimal type.	zines/how.integers.and.floats.work.wizard.zines.cleaned.notes
binary/c9f0a1b2d3e4	binary	medium	binary,floats,structure	What are the three components of an IEEE floating point number?	Sign bit, exponent, and significand (mantissa). Together they represent the value as sign * significand * 2^exponent.\n\nRemember: 'SEM — Sign, Exponent, Mantissa.' float32: 1 sign + 8 exponent + 23 mantissa = 32 bits. float64: 1+11+52 = 64 bits.\n\nExample: the number -6.5 = -1 * 1.625 * 2^2. Sign=1, exponent=2+127=129, mantissa=.625 encoded as 101 followed by zeros.	zines/how.integers.and.floats.work.wizard.zines.cleaned.notes
binary/d0a1b2c3e4f5	binary	hard	binary,floats,density	Why are floating point numbers denser near zero?	Because the exponent scales the gap between representable values. Small exponents produce small gaps; large exponents produce large gaps. Precision is not uniform across the range.\n\nRemember: 'Small exponent = small gaps, large exponent = large gaps.' Half of all float values lie between -1 and 1.\n\nGotcha: between 2^23 and 2^24 (for float32), consecutive floats differ by 1.0 — you cannot represent 8388609.5.	zines/how.integers.and.floats.work.wizard.zines.cleaned.notes
binary/e1b2c3d4f5a6	binary	medium	binary,nan,floats	What is NaN and what is unusual about comparing it?	NaN (Not a Number) is a special float value produced by invalid operations like 0/0. It is unique in that NaN != NaN evaluates to true — it is not equal to itself.\n\nRemember: NaN != NaN is the only value in IEEE 754 that is not equal to itself. Use math.isnan() or x != x to detect it.\n\nGotcha: NaN propagates — any arithmetic with NaN produces NaN. One bad sensor reading can corrupt an entire pipeline.	zines/how.integers.and.floats.work.wizard.zines.cleaned.notes
binary/f2c3d4e5a6b7	binary	hard	binary,floats,money	Why should you avoid using floating point for monetary calculations?	Floats cannot exactly represent many decimal fractions (like 0.10), leading to rounding errors that accumulate. Use fixed-point decimal types or integer cents instead.\n\nExample: $0.10 * 3 in float might give $0.30000000000000004. Store as integer cents: 10 * 3 = 30 cents. Display at the end.\n\nRemember: 'Cents not floats.' Python: decimal.Decimal, Java: BigDecimal, PostgreSQL: NUMERIC. Never IEEE 754 for money.	zines/how.integers.and.floats.work.wizard.zines.cleaned.notes
binary/a3d4e5f6b7c8	binary	medium	binary,floats,equality	What is the safe way to compare floating point values?	Compare within a tolerance (epsilon), not with exact equality, unless you can guarantee exact representation. For example: abs(a - b) < epsilon.\n\nExample: abs(a - b) < 1e-9 for double precision. The epsilon should scale with the magnitude of the values being compared.\n\nGotcha: a fixed epsilon breaks for very large or very small numbers. Use relative epsilon: abs(a-b) / max(abs(a), abs(b)) < epsilon.	zines/how.integers.and.floats.work.wizard.zines.cleaned.notes
binary/b4e5f6a7c8d9	binary	medium	binary,bitwise,operations	What are the core bitwise operators and a common use case?	AND, OR, XOR, NOT, and bit shifts. Common uses include bitmask flags, permissions (like Unix file modes), compact state storage, and parsing protocol fields.\n\nRemember: AND=mask, OR=set, XOR=toggle, NOT=invert, SHIFT=multiply/divide by powers of 2.\n\nExample: Unix permissions use bitmasks — chmod 755 = rwxr-xr-x = 111 101 101 in binary.	zines/how.integers.and.floats.work.wizard.zines.cleaned.notes
binary/c5f6a7b8d9e0	binary	easy	binary,hexadecimal,conversion	What decimal value does 0xff represent?	255 (15*16 + 15, or all 8 bits set to 1).\n\nRemember: F in hex = 15 = 1111 in binary. 0xFF = 15*16 + 15 = 255 = all 8 bits set.\n\nExample: 0xFF is used as a bitmask to extract the lowest byte: value & 0xFF gives the last 8 bits.\n\nFun fact: 0xDEADBEEF, 0xCAFEBABE (Java class files), and 0xFEEDFACE (Mach-O binaries) are famous hex magic numbers.	zines/how.integers.and.floats.work.wizard.zines.cleaned.notes
binary/c21f60deabd0	binary	medium	binary;endianness	What is byte order (endianness) and why does it matter in network programming?	Endianness is the order bytes are stored in memory. Big-endian (MSB first) is network byte order. Little-endian (LSB first) is common on x86. Mismatched endianness corrupts multi-byte values across systems.\n\nRemember: 'Big-endian = big end first' (MSB at lowest address). Network byte order is always big-endian (RFC 791).\n\nFun fact: the terms come from Gulliver's Travels — the Lilliputians fought over which end of an egg to crack first.	
binary/90947bc0bd25	binary	hard	binary;twos-complement	How does two's complement represent negative integers, and what is -1 in 8-bit two's complement?	Two's complement inverts all bits and adds 1. For -1: start with 00000001, invert to 11111110, add 1 = 11111111 (0xFF). This scheme allows addition of positive and negative numbers using the same hardware.\n\nRemember: 'Flip and add one' — that's the two's complement recipe. -1 is always all-ones (0xFF for 8-bit, 0xFFFFFFFF for 32-bit).\n\nGotcha: -1 in any width two's complement is all 1-bits. This is why bitwise NOT of 0 equals -1 in signed integers.	
binary/207b287a41cf	binary	medium	binary;hex	Why is hexadecimal commonly used to represent binary data?	Each hex digit represents exactly 4 bits (one nibble), so 1 byte = 2 hex digits. This is more compact than binary (8 digits) and groups cleanly on byte boundaries, unlike octal.\n\nRemember: 1 hex digit = 4 bits = 1 nibble. 2 hex digits = 1 byte. So 0xFF = 1111 1111 = 255.\n\nExample: MAC addresses (aa:bb:cc:dd:ee:ff), IPv6, memory addresses, and color codes (#FF0000) all use hex.	
binary/b3503ff04aa4	binary	medium	binary;bitwise	What do the bitwise AND, OR, and XOR operators do, and name one use case for each?	AND (&): mask bits (extract specific bits). OR (|): set bits (enable flags). XOR (^): toggle bits (simple encryption, swap without temp variable). All operate bit-by-bit on integer operands.\n\nRemember: AND(&)=mask/extract, OR(|)=set/enable, XOR(^)=toggle/flip. Mnemonic: 'AOX = And filters Out, Or adds, Xor toggles.'\n\nExample: checking if bit 3 is set: (flags & 0x08) != 0. Setting bit 3: flags |= 0x08. Toggling: flags ^= 0x08.	
binary/468f1e562e5a	binary	medium	binary;alignment	What is memory alignment and why do compilers add padding to structs?	Memory alignment means placing data at addresses divisible by its size (e.g., 4-byte int at 4-byte boundary). CPUs access aligned data faster. Compilers pad structs to maintain alignment, which can increase struct size.\n\nExample: struct { char a; int b; } is 8 bytes, not 5 — the compiler adds 3 padding bytes after 'a' to align 'b' on a 4-byte boundary.\n\nGotcha: reordering struct fields from largest to smallest minimizes padding. Tools like pahole show struct layouts.	

<!-- wiki:related:start -->
---

## Wiki Navigation

### Related Content

- [Binary and Floats](../../../../library/topics/binary-and-floats/index.md) (Topic Pack, L1) — Binary & Number Representation

<!-- wiki:related:end -->
