Chapter 1.2: Number Systems
Multiple Choice · Number Representation
Question 1: A Roman Numeral
What is the decimal value of the number written in Roman numerals as MCMXLIV?
C: M = 1000, CM = 1000 − 100 = 900, XL = 50 − 10 = 40, IV = 5 − 1 = 4 → 1944. A smaller symbol before a larger one is subtracted. 1964 reads XL as 60 (LX); 2144 counts CM as 1100; 1946 reads IV as 6 (VI).
Classic Question · Positional Systems
Question 2: Digit Weights
What is the decimal value of each of the following numbers?
a) 01101011b b) 1111011b c) 1ABh d) 512Fh
Show answer
- a) 64 + 32 + 8 + 2 + 1 = 107 (= 6Bh: 0110 1011)
- b) 64 + 32 + 16 + 8 + 2 + 1 = 123 (= 7Bh)
- c) 1·16² + A·16 + B = 256 + 160 + 11 = 427
- d) 5·16³ + 1·16² + 2·16 + F = 20,480 + 256 + 32 + 15 = 20,783
In binary numbers, add up the weights of the digits that are 1. Grouping in fours is also a shortcut: 0110 1011 = 6Bh = 6·16 + 11 = 107. In hexadecimal, A … F = 10 … 15.
Multiple Choice · Positional Systems
Question 3: Writing Numbers
Which of the following instructions loads AL with a value different from the others?
D: Without a suffix the number is decimal: 41 = 29h. The other three write the same value (65 = 41h = 'A') in different bases: 0100 0001b = 41h, 101o = 64 + 1 = 65. The base is only a way of writing; in machine code everything is binary.
Step-by-Step Trace · Base Conversions
Question 4: 2024 → Hexadecimal and Binary
The number 2024 is converted to hexadecimal by repeated division by 16. What is the result? How is the binary equivalent found?
The decimal number is divided by the base (16); the remainders give the hexadecimal digits.
2024 = 16 × 126 + 8. Remainder 8 = 8h; it is prepended to the result.
126 = 16 × 7 + 14. Remainder 14 = Eh; it is prepended to the result.
7 = 16 × 0 + 7. Remainder 7 = 7h; it is prepended to the result. The quotient is 0: the loop ends.
The remainders are read from bottom to top: 7E8h. Each hexadecimal digit expands to 4 bits: 7 = 0111, E = 1110, 8 = 1000. Check: 7·256 + 14·16 + 8 = 2024.
n = 2024; result = "" while (n > 0) { remainder = n % 16; n = n / 16; // integer division result = digit(remainder) + result; }
Classic Question · Base Conversions
Question 5: Fractions
a) Convert 0.6875 to binary.
b) Write 13.375 in binary and hexadecimal.
c) What are the first 8 fraction bits of 0.3? Is it finite in binary?
Show answer
- a) 0.6875·2 = 1.375 → 1; 0.375·2 = 0.75 → 0; 0.75·2 = 1.5 → 1; 0.5·2 = 1.0 → 1 → 0.1011b (½ + ⅛ + 1/16)
- b) 13 = 1101b; 0.375 → 0.011b → 1101.011b. Group in fours outward from the point: 1101 . 0110 → D.6h
- c) 0.6 → 0; 1.2 → 1; 0.4 → 0; 0.8 → 0; 1.6 → 1; 1.2 → 1; 0.4 → 0; 0.8 → 0 → 0.01001100b. Because the fraction 0.2 appears a second time, the pattern 1001 repeats forever: it is not finite.
The integer part is converted by division, the fractional part by multiplying by 2; the fraction bits are read from top to bottom.
Multiple Choice · Signed Numbers
Question 6: Signed Interpretation
What are the unsigned and signed (two's complement) interpretations of the 8-bit value 1111 1011b (FBh)?
B: Unsigned: 128 + 64 + 32 + 16 + 8 + 2 + 1 = 251. Signed: MSB = 1 → negative; the value is 251 − 256 = −5 (or invert + 1: 0000 0101 = 5). −123 is the sign-magnitude reading, which treats the sign bit merely as “minus”; −4 is the one's complement reading.
Classic Question · Signed Numbers
Question 7: One's and Two's Complement
In an 8-bit system, find
a) for 21 and 20: the one's complement,
b) for 25 and 30: the two's complement (binary and hexadecimal).
Show answer
- a) 21 = 0001 0101 → bits inverted: 1110 1010 (EAh); 20 = 0001 0100 → 1110 1011 (EBh)
- b) 25 = 0001 1001 → inverted 1110 0110 → +1 → 1110 0111 (E7h); 30 = 0001 1110 → inverted 1110 0001 → +1 → 1110 0010 (E2h)
Check: 256 − 25 = 231 = E7h, 256 − 30 = 226 = E2h. On the 8086 the one's complement is NOT and the two's complement is NEG. Shortcut: copy the bits from the right up to and including the first 1, then invert the rest.
Multiple Choice · Signed Numbers
Question 8: −100 in 16 Bits
What is the 16-bit two's complement representation of −100?
A: 65536 − 100 = 65436 = FF9Ch. The 8-bit representation is 9Ch; sign extension to 16 bits (the MSB is copied to the left) gives FF9Ch: CBW does exactly this. 009Ch is zero extension (+156); 809Ch merely sets the sign bit to 1; FF64h is −156.
Classic Question · Signed Numbers
Question 9: A Fixed-Point Fraction
In the 8-bit Q5.3 format (the last 3 bits are the fraction, the leftmost bit is the sign bit):
a) How is −2.375 written (binary and hexadecimal)?
b) What value does 11010.100b (D4h) represent?
Show answer
- a) 2.375 · 2³ = 19 → −19 = 256 − 19 = 237 = EDh → point 3 bits from the right: 11101.101b. Check: −16 + 8 + 4 + 1 + 0.5 + 0.125 = −2.375
- b) Weights −16, 8, 4, 2, 1, ½, ¼, ⅛: −16 + 8 + 2 + 0.5 = −5.5. Or D4h = 212 − 256 = −44 → −44 / 8 = −5.5
To the processor these bytes are ordinary integers; the position of the binary point is the programmer's convention. Range −16 … +15.875, step 0.125.
Multiple Choice · Binary Arithmetic
Question 10: Carry or Overflow?
While AL = 64h, ADD AL, 3Ch executes. What are the result and the flags?
C: 64h + 3Ch = A0h (100 + 60 = 160 ≤ 255): the unsigned result fits, so CF = 0. In the signed interpretation the sum of two positive numbers came out negative (A0h = −96): +160 does not fit, so OF = 1. CF flags unsigned overflow, OF flags signed overflow.
Step-by-Step Trace · Binary Arithmetic
Question 11: Hexadecimal Addition
What is the sum 6D8Ah + 2C9Fh? If the same operation were done with ADD AX, BX, what would CF and OF be?
A = 6D8Ah, B = 2C9Fh. Addition starts at the rightmost digit; carry 0.
A + F + 0 = 25 ≥ 16 → write 25 − 16 = 9 (9) in the digit, carry 1.
8 + 9 + 1 = 18 ≥ 16 → write 18 − 16 = 2 (2) in the digit, carry 1.
D + C + 1 = 26 ≥ 16 → write 26 − 16 = 10 (A) in the digit, carry 1.
6 + 2 + 1 = 9 < 16 → write 9, no carry.
The sum is 9A29h. No carry came out of the last digit → CF = 0. In the signed interpretation the sum of two positive numbers came out negative (MSB = 1) → OF = 1 (28042 + 11423 = 39465 > 32767).
carry = 0; // i = 0: rightmost digit for (i = 0; i < 4; i++) { t = A[i] + B[i] + carry; S[i] = t % 16; carry = t / 16; } // ADD AX, BX: CF = carry
Classic Question · Binary Arithmetic
Question 12: Subtraction with the 16's Complement
Find 4A2Ch − 6B57h by adding the 16's complement. Is the result positive or negative? What are AX and CF after SUB AX, BX (AX = 4A2Ch, BX = 6B57h)?
Show answer
- The 15's complement of 6B57h: F−6, F−B, F−5, F−7 → 94A8h; +1 → the 16's complement 94A9h
- 4A2Ch + 94A9h = DED5h; no carry beyond 4 digits → the result is negative
- Magnitude: the 16's complement of DED5h is 212Bh → the difference is −212Bh (−8491)
SUB AX, BX: AX = DED5h (−8491 in the signed interpretation); a borrow occurred, so CF = 1
Multiple Choice · Codes and Circuits
Question 13: Decoding IEEE 754
Which decimal value does the 32-bit IEEE 754 number 41200000h represent?
B: 41200000h = 0 10000010 0100…0. Sign 0 → positive. Exponent 1000 0010b = 130 → 130 − 127 = 3. Mantissa 0.01b → 1.25 with the hidden bit. Value 1.25 × 2³ = 10. 5 and 20 take the exponent one too small or one too large; 2.5 treats the exponent bias as 129.
Classic Question · Codes and Circuits
Question 14: Encoding IEEE 754
Write −12.25 in 32-bit IEEE 754 format in binary and hexadecimal.
Show answer
- Sign: negative → 1
- 12.25 = 1100.01b = 1.10001b × 2³ (normalized)
- Exponent: 3 + 127 = 130 = 1000 0010b
- Mantissa: the hidden 1 is dropped → 1000 1000 0000 0000 0000 000
- 1 10000010 10001000000000000000000 = 1100 0001 0100 0100 0000 … → C1440000h
In memory, little-endian, it is stored in the order 00 00 44 C1. The 8086 has no floating-point instructions; the 8087 coprocessor or software works with this format.
Multiple Choice · Codes and Circuits
Question 15: BCD Addition
AL = 29h and BL = 18h are packed BCD numbers (29 and 18). After ADD AL, BL and then DAA execute, what is AL?
C: The binary sum is 29h + 18h = 41h; because the low nibble produced a carry, AF = 1. DAA adds 6 to the low digit: 41h + 6 = 47h → BCD 47 = 29 + 18. 41h is the uncorrected result; 2Fh is the binary equivalent of decimal 47 (not BCD).
Multiple Choice · Codes and Circuits
Question 16: Gray Code
What is the 4-bit Gray code of 1011b (11)?
A: G = B XOR (B >> 1) = 1011 ⊕ 0101 = 1110. The top bit stays the same; each following bit is the XOR of that bit in the binary number with the bit to its left: 1, 1⊕0 = 1, 0⊕1 = 1, 1⊕1 = 0. 0100 is the one's complement.
Output Question · Codes and Circuits
Question 17: Little-Endian
The 32-bit value A1B2C3D4h was stored at DS:0300h with DD. a) What are the bytes at 0300h … 0303h? How would they look on a big-endian processor? b) After the code runs, what are AX, BL and CX?
ORG 100h MOV AX, [0302h] MOV BL, [0301h] MOV CX, [0301h] RET
Show answer
- a) Little-endian (8086): 0300: D4, 0301: C3, 0302: B2, 0303: A1. Big-endian: A1 B2 C3 D4.
- b)
MOV AX, [0302h]: AL ← B2h, AH ← A1h → AX = A1B2h MOV BL, [0301h]: a single byte → BL = C3hMOV CX, [0301h]: CL ← [0301h] = C3h, CH ← [0302h] = B2h → CX = B2C3h (an unaligned word read)
Multiple Choice · Codes and Circuits
Question 18: The JK Flip-Flop
The output of a JK flip-flop starts at Q = 0. With J = K = 1 held, 3 rising clock edges arrive. What is Q afterward?
D: In a JK flip-flop, J = K = 1 is the toggle state: Q is inverted on every edge: 0 → 1 → 0 → 1. The forbidden state is S = R = 1 in the SR flip-flop; the JK defines it as toggling. That is why T flip-flops and counters can be built from JK flip-flops.