Chapters & sections

CHAPTER 1 · HARDWARE

Data Representation in Computers

Original textbook · pp. 20–45

Represent information with bits, convert number bases and reason about signed values, floating point, errors and shifts.

6 related published questions

The same bit pattern can represent a number, a character, an instruction or a color. Its meaning comes from the encoding and context. Start with the capacity of a bit pattern, then work through positional notation, numeric formats, errors and operations on bits.

Data Representation

Original textbook · pp. 20–23

A bit has two possible values, 0 and 1. A byte is eight bits. A word is a processor’s natural grouping for some operations; its width depends on the architecture. Do not assume that the word size, address width and external bus width must all be identical.

Each additional independent bit doubles the number of available patterns. With n bits there are 2n patterns. An unsigned integer uses these for values from 0 through 2n − 1. Eight bits provide 256 patterns, but the greatest unsigned value is 255, because zero is one of the values.

Worked example. A code needs to identify 40 equipment types. Five bits offer only 32 patterns; six offer 64. The minimum width is therefore six bits. Unused patterns do not automatically create additional equipment types: they are simply codes available for future use or error detection.

Information amount can also describe surprise. An event of probability p carries self-information I = −log2(p) bits. An event with probability 1/8 carries three bits of information. This is different from saying that every stored record occupies three bits: storage format and event probability answer different questions.

Unit or prefix Meaning Example
B and bit Bytes and bits are different units 16 B = 128 bits
k, M, G, T, P Decimal powers 10³, 10⁶, 10⁹, 10¹², 10¹⁵ 1 MB = 1,000,000 B in decimal notation
Ki, Mi, Gi, Ti, Pi Binary powers 2¹⁰, 2²⁰, 2³⁰, 2⁴⁰, 2⁵⁰ 1 MiB = 1,048,576 B
ms, µs, ns, ps 10⁻³, 10⁻⁶, 10⁻⁹, 10⁻¹² seconds 2 µs = 2,000 ns

Older descriptions and exam problems sometimes use KB or MB for binary quantities. Always follow an explicit definition in the question. Never silently mix bits/s with bytes/s or milliseconds with seconds.

Bits, patterns and a byteA binary tree doubles from two one-bit choices to four two-bit choices. Eight bit cells form one byte, with 256 possible patterns and unsigned values 0 to 255.1 bit → 2 patterns01000110112 bits → 4 patterns101001011 byte = 8 bits = 256 patterns
Bits, patterns and a byte. Each independent bit doubles the pattern count. Eight bits give 256 patterns, not a greatest unsigned value of 256.Original textbook · pp. 20–21

Radix and Radix Conversion

Original textbook · pp. 23–28

In a positional number system, each digit has a weight that is a power of the radix, or base. The units digit has weight b0 = 1. Moving left multiplies the weight by b; moving right across the radix point divides by b. The allowed digits are 0 through b − 1.

Base Allowed digits Weights near the radix point
Binary, 2 0, 1 8, 4, 2, 1 . 1/2, 1/4, 1/8
Octal, 8 0–7 512, 64, 8, 1 . 1/8, 1/64
Decimal, 10 0–9 1,000, 100, 10, 1 . 1/10, 1/100
Hexadecimal, 16 0–9 and A–F 4,096, 256, 16, 1 . 1/16, 1/256

Hexadecimal A through F stand for decimal 10 through 15. They are digits, not variables in this notation. A subscript such as (2B)16 makes the base explicit.

Radix conversion ↗ · 3 questions to decimal means multiplying each digit by its positional weight and adding. For example, (2B.8)16 = 2 × 16 + 11 × 1 + 8/16 = 43.5. The digit after the point is not a decimal tenth.

Decimal to binary: 26.625. For the integer part, repeatedly divide by two: 26→13 remainder 0; 13→6 remainder 1; 6→3 remainder 0; 3→1 remainder 1; 1→0 remainder 1. Read the remainders upward: 11010.

For the fractional part, repeatedly multiply by two and record each integer part: 0.625×2 = 1.25 gives 1; 0.25×2 = 0.5 gives 0; 0.5×2 = 1 gives 1. Read these in the order produced: .101. Thus 26.625 = (11010.101)2. Check by summing 16 + 8 + 2 + 1/2 + 1/8.

Read integer and fraction digits differentlyRepeated division of 26 by two yields remainders 0,1,0,1,1, read upward as 11010. Repeated multiplication of 0.625 by two yields integer parts 1,0,1, read downward as .101.26: divide by 226 → 13, remainder 013 → 6, remainder 16 → 3, remainder 03 → 1, remainder 11 → 0, remainder 10.625: multiply by 20.625 × 2 = 1.25 → 10.25 × 2 = 0.5 → 00.5 × 2 = 1.0 → 1Integer ↑ Fraction ↓
Read integer and fraction digits differently. Integer remainders are read from the final division back upward. Fractional integer parts are read in the order generated. The result is 11010.101₂.Original textbook · pp. 26–27

To convert between binary and hexadecimal, group bits in fours outward from the radix point. For octal, group them in threes. Add zeros only at the outside ends where they do not change the value. For example, (101101.01)2 becomes (0010 1101 . 0100)2 = (2D.4)16. Appending a zero to the right end of a fraction is harmless; appending one to an integer multiplies it by two.

Not every terminating decimal fraction terminates in binary. For example, 1/10 has a repeating binary expansion. A finite representation must then round or truncate; the error is a consequence of the chosen format, not a failure of the conversion method.

Group from the radix pointThe same binary pattern 101101.101 is grouped as 101 101 point 101 for octal 55.5 and as 0010 1101 point 1010 for hexadecimal 2D.A. Only outer padding zeros are added.Binary: 101101.101Octal: groups of 3101 | 101 . 1015 5 . 5Hex: groups of 40010 | 1101 . 10102 D . A
Group from the radix point. Three binary digits select one octal digit; four select one hexadecimal digit. Group separately on each side of the point, padding only the outer ends.Original textbook · pp. 24–25
A recurring remainder creates recurring bitsStarting with decimal fraction 0.1, repeated multiplication by two emits bits 0,0,0,1,1 and leaves remainders 0.2,0.4,0.8,0.6,0.2. The remainder 0.2 repeats, so subsequent bits repeat 0011.Fraction × 2 → bit, remainder0.1 × 2 → 0, 0.20.2 × 2 → 0, 0.40.4 × 2 → 0, 0.80.8 × 2 → 1, 0.60.6 × 2 → 1, 0.2Remainder 0.2 repeats → loop
A recurring remainder creates recurring bits. 0.1₁₀ = 0.000110011…₂. Once the same fractional remainder returns, the subsequent digits repeat. Finite storage must round or truncate this expansion.Original textbook · p. 28

Representation Form of Data

Original textbook · pp. 28–45

Before interpreting bytes, identify the format. The byte 01000001 can be the unsigned number 65 or an encoded letter A in ASCII. Neither interpretation follows from the bits alone. Correctly moving bytes does not ensure correctly interpreting them.

The meaning comes from the formatData branches into character codes and numeric formats. Numeric formats branch into decimal digit codes and binary formats, with fixed point and floating point under binary.DataCharactersNumbersDecimal codesBinaryFixed pointFloating point
The meaning comes from the format. A bit pattern has no intrinsic character or numeric meaning. The selected format determines how those bits are interpreted.Original textbook · p. 28

Character Data

Original textbook · pp. 29–31

A character code associates a written symbol or control function with a value. ASCII is a seven-bit code with 128 positions. EBCDIC is a different historical code family; a byte meaningful under one encoding can mean something else under another. JIS, Shift JIS and EUC are important in the history of Japanese character representation. Do not assume that all character encodings use one byte per character.

Unicode assigns code points, such as U+0041 for A. An encoding such as UTF-8 turns code points into code units or bytes. UTF-8 uses one to four bytes per Unicode scalar value; the familiar ASCII subset uses one byte. A displayed symbol may combine several code points, so byte count, code-point count and displayed-character count can differ. Encoding and font are also different: the encoding identifies characters; a font supplies their visual forms.

Concrete example. The text “AB” takes two bytes in UTF-8 without a terminator or other overhead. A two-symbol string containing non-ASCII symbols need not take two bytes. When estimating file size, use the specified encoding and count what the question actually asks for.

A character code is a lookupThe Latin capital letter A is U+0041 in Unicode and 0x41 in ASCII. Its UTF-8 byte is hexadecimal 41, binary 01000001. A grid uses high nibble 4 and low nibble 1 to locate hexadecimal 41.AUnicode: U+0041ASCII / UTF-8 byte: 0x4101000001High nibble 4; low nibble 14 × 16 + 1 = 65
A character code is a lookup. Split the byte into two nibbles to locate its hexadecimal code. A code point and an encoded byte sequence are different concepts.Original textbook · p. 30

Numeric Data

Original textbook · pp. 31–41

Decimal-coded numbers. In binary-coded decimal (BCD), each decimal digit has its own four-bit code. Decimal 58 becomes 0101 1000 in BCD, whereas the ordinary binary integer 58 is 00111010. Codes 1010 through 1111 are not decimal digit codes. Packed decimal stores two digit-sized nibbles per byte, often reserving a final nibble for a sign; a common convention uses hexadecimal C for positive and D for negative. Zoned decimal uses a byte for each decimal digit, with zone/sign information. The exact sign convention is part of the format, not a universal meaning of the bit pattern.

Fixed-point numbers have an agreed radix-point position. If an unsigned eight-bit value has four fractional bits, stored integer 24 represents 24/16 = 1.5. The precision step is 1/16. Increasing fractional precision without increasing the total width reduces the available integer range.

Signed integer format How a negative value is encoded Eight-bit range
Sign and magnitude One sign bit plus the absolute value −127 to +127, with two zeros
One’s complement Invert all bits of the positive representation −127 to +127, with two zeros
Two’s complement Invert the positive representation and add one −128 to +127, with one zero

In eight-bit two’s complement, +5 is 00000101. Invert to 11111010 and add one to get −5 = 11111011. Another interpretation is that the most significant bit has weight −128 and the remaining bits have weights 64 through 1: −128 + 64 + 32 + 16 + 8 + 2 + 1 = −5. Sign extension repeats the sign bit when increasing the width.

Addition uses the same binary adder for positive and negative values. For example, 7 + (−5) = 00000111 + 11111011 = 1 00000010; discard the carry beyond the eight-bit width to obtain 2. A carry-out and signed overflow are different: adding two positive numbers and obtaining a negative result is signed overflow even if there is no carry-out.

Decimal digits packed into nibblesDecimal 672 becomes BCD nibbles 0110, 0111, 0010. A common signed packed representation is hexadecimal 67 2C for positive 672. EBCDIC-style zoned positive digits are F6 F7 C2, with the final zone holding the sign.Decimal digits: 6 7 2BCD: one nibble per digit0110 | 0111 | 0010Packed: 67 | 2CC = positive sign nibbleZoned: F6 | F7 | C2Pack / unpack for I/O formats
Decimal digits packed into nibbles. In this explicitly chosen convention, C is a positive sign and D a negative sign. Packed 67 2C uses two bytes; zoned F6 F7 C2 uses three. Sign codes depend on the format.Original textbook · pp. 32–33
Two signed four-bit interpretationsFor four bits, sign-magnitude uses 0000 for plus zero and 1000 for minus zero, spanning minus 7 to plus 7. Two’s complement uses one zero, spans minus 8 to plus 7, and gives 1000 the value minus 8.Four bits: 16 patternsSign-magnitude−7 … −0, +0 … +7Two’s complement−8 … −1, 0 … +71000 = −8; 0111 = +7
Two signed four-bit interpretations. The same 1000 pattern means −0 in sign-magnitude and −8 in two’s complement. Two’s complement uses all 16 patterns for 16 distinct integer values.Original textbook · pp. 34–35, 37

Floating-point representation ↗ · 1 question stores a sign, an exponent and a significand. It allows a wide range of magnitudes, but gives finite precision. A normalized binary number has a nonzero leading digit; for a normal binary IEEE 754 value that leading digit is 1.

Sign
1 bit
Biased exponent
8 bits
Stored fraction
23 bits
Original field diagram: 32 bits in total. The leading 1 of a normal significand is implicit.

For a normal binary32 value, with 0 < E < 255:

value = (−1)S × 2E − 127 × (1 + F)

Here F is the binary fraction encoded by the 23 stored bits. For 10.5, binary 1010.1 normalizes to 1.0101 × 2³. Therefore S=0, E=3+127=130, and the stored fraction begins 0101 followed by zeros. The implicit leading 1 must not be counted again in F or omitted from the significand.

Exponent fields of all zeros or all ones are special cases: zeros/subnormal numbers, infinities and NaNs do not all follow the normal-number formula. An exam may deliberately restrict E so that only the normal case is relevant. Read that restriction before decoding the fields.

Normalize, then store the fieldsBinary 1010.1 normalizes to 1.0101 times two cubed. For binary32 the sign is zero, biased exponent is 130 and the stored fraction begins 0101. Binary32 has field widths 1,8,23; binary64 has 1,11,52 and bias 1023.10.5 = 1010.1₂1.0101₂ × 2³Binary32: S=0; E=3+127=130Stored fraction: 0101…32 bits: 1 + 8 + 2364 bits: 1 + 11 + 52Binary64 exponent bias: 1023
Normalize, then store the fields. For normal finite values, the leading 1 is implicit. Binary32 has 24 significant binary digits including that 1; binary64 has 53. Zero/subnormal and all-ones exponent fields need separate rules.Original textbook · pp. 38–40

Error

Original textbook · pp. 41–43

Finite formats have range and precision limits. Overflow exceeds the available range. Underflow concerns a nonzero magnitude too small for the format’s normal range; some formats support subnormal values with reduced precision. Rounding error arises when an exact value is replaced with a nearby representable value. Truncation error can arise when a computation or expansion is cut short.

Cancellation, or loss of significant digits, occurs when nearly equal rounded values are subtracted. Suppose measurements rounded to four significant digits are 1.234 and 1.233: their difference has very little reliable precision. Loss of trailing digits can occur when a small value is added to a much larger floating-point value and falls beyond its precision. The small quantity was not necessarily zero; the selected format could not retain its effect on that sum.

Absolute error = |approximation − exact value|. Relative error divides that amount by |exact value|, when the exact value is nonzero. Approximating 2/3 by 0.67 gives absolute error about 0.00333 and relative error about 0.005, or 0.5%. State whether an error measure is a fraction or a percentage.

Use more suitable precision, avoid subtracting nearly equal quantities where an equivalent stable expression exists, and consider adding smaller-magnitude terms first. These can reduce error; they do not turn finite arithmetic into exact real-number arithmetic.

Precision and range are different limitsWith three significant decimal digits, 1.234 rounds to 1.23. Subtracting the rounded 1.234 and 1.233 gives zero instead of the exact 0.001. Adding 1 to 1.00 million can lose the small term. Underflow concerns tiny magnitudes near zero; overflow concerns excessive magnitude of either sign.Round: 1.234 → 1.23Cancellation after rounding:1.23 − 1.23 = 0Small term may disappear:1.00 × 10⁶ + 1 → 1.00 × 10⁶Underflow: tiny |value|Overflow: excessive |value|
Precision and range are different limits. Illustrative three-significant-digit decimal arithmetic. Cancellation and lost small terms concern precision. Underflow concerns tiny magnitudes near zero, not simply any value below a signed minimum.Original textbook · pp. 41–42

Shift Operation

Original textbook · pp. 43–45

A logical shift moves bits and fills vacated positions with zeros. A rotation moves bits around the ends instead of discarding them. An arithmetic right shift repeats the sign bit of a two’s-complement value to preserve its sign. For example, eight-bit −8 = 11111000 becomes 11111100, or −4, after one arithmetic right shift. Shifting a negative odd value right can round differently from division that truncates toward zero.

For an integer whose result remains representable, a left shift by k positions multiplies by 2k. In a fixed-width machine, discarded high bits can cause overflow, so the mathematical identity needs that qualification. Some textbook descriptions reserve the sign bit when illustrating arithmetic shifts; follow the word width and shifting rule stated in the question.

Signed integers and shifts ↗ · 1 question let us replace certain multiplications with powers of two. For example, 13n = 8n + 4n + n = (n shifted left 3) + (n shifted left 2) + n, subject to sufficient width. Work out the algebra before moving bits.

Three ways to shift rightStarting with 10010110, logical right shift inserts zero to give 01001011; arithmetic right shift repeats one to give 11001011; rotate right wraps the discarded zero to give 01001011. Rotation differs from a shift even when this example’s results match.Start: 10010110Logical: insert 001001011Arithmetic: repeat sign 111001011Rotate: wrap outgoing 001001011
Three ways to shift right. Eight-bit operations, shifted once. Logical fill is zero; arithmetic right fill repeats the sign; rotation wraps the outgoing bit. Left shifts can discard significant bits and overflow.Original textbook · pp. 43–45

Bit masks ↗ · 1 question select individual positions. AND with 1 retains a bit; AND with 0 clears it. OR with 1 sets a bit. XOR with 1 toggles a bit. NOT reverses every bit within the selected width.

For source 10110110 and mask 11110000, AND gives 10110000. This retains the upper four bits in place; it does not move them into the low positions. An additional four-bit logical right shift would produce 00001011. Distinguishing “retain,” “clear” and “shift” prevents a common exam mistake.

KEEP LEARNING

Ready to test the idea?

Try 6 related published questions. You can return to this exact place.

Your reading and practice progress stay on this device.

Original explanations, worked examples and diagrams. Topic order and printed-page references follow New FE Textbook Vol.1 · IT Fundamentals · First Edition, April 2015. Exam images retain original source attribution.