Mathematics for Computer Science 201-N11 • CEGEP, Montreal

Corrected exercises: number systems in computing (201-N11)

This is the corrected exercise set on number systems for Mathematics for Computer Science, 201-N11, the mathematics course taken by CEGEP students in computer science programs (Computer Science Technology, and Computer Science and Mathematics). Part A covers the basics: positional weights and reading a number in its base, repeated division and repeated multiplication to convert from decimal, binary arithmetic worked by hand, two's complement and its asymmetric range, then overflow and the rule that detects it. Two complete labs take the whole route again in base 8 (exercise 5) and in base 16 (exercise 6): expanded notation, conversions from octal and hexadecimal to decimal and back, addition, 8's and 16's complements, subtraction with borrows, long multiplication and a round trip checked in decimal, all the way to Linux permissions chmod 755.

Part B moves up to exam level: hexadecimal as a compact way of writing binary, with masks and shifts (exercise 8), the ASCII, BCD and Gray codes and the parity bit, with the limitation that leads to the Hamming code (exercise 9), a problem on screen colours and memory capacity (exercise 11), and the complete construction of an IEEE 754 single-precision floating-point number (exercise 12).

The thread of the set: the base gives the weight of each position, so converting means weighing. Every conversion is checked by adding up the weights again, and that check catches both the remainders read in the wrong order and the groups of bits cut from the left.

The pitfalls named explicitly in the solutions: believing that a bit pattern carries its own interpretation, forgetting that the signed range is asymmetric because zero takes up one slot, confusing the unsigned carry with signed overflow (exercise 7), and thinking that 0.10.1 will end up being written exactly in binary if enough bits are added (exercises 2 and 10).

12 corrected exercises • 120 points • 180 minutes

This chapter is part of 201-N11, every chapter with its set and sheet Before you start Revision sheet: the traps and the method for this chapter

Self-checking set Type your answers and check them question by question: the page tells you right or wrong before you open the solution. With an account, every answer right on the first try earns points, and your right answers stay filled in when you come back.

Course recap

  • • In base bb, the digit in position kk has weight bkb^{k}; after the radix point, the weights are b−1,b−2,…b^{-1}, b^{-2}, \dots
  • • Decimal to base bb: repeated division, remainders read from BOTTOM TO TOP. Fractional part: repeated multiplication, integer parts read from TOP TO BOTTOM.
  • • One hexadecimal digit is 4 bits, one octal digit is 3 bits. Always group the bits starting from the RIGHT.
  • • Unsigned, on nn bits: from 00 to 2n−12^{n}-1. In two's complement: from −2n−1-2^{n-1} to 2n−1−12^{n-1}-1.
  • • Two's complement of xx: invert all the bits, then add 1. The resulting pattern equals 2n−x2^{n}-x.
  • • Signed overflow: both operands have the same sign and the result has the opposite sign. Two operands of opposite signs never overflow.
  • • AND to clear bits, OR to set them, XOR to toggle them.
  • • Shifting left by kk positions: multiplication by 2k2^{k}. Shifting right: integer division by 2k2^{k}.
  • • A terminating decimal has a terminating binary expansion only if its reduced denominator is a power of 2.
  • • IEEE 754 single precision: 1 sign bit, 8 exponent bits with a bias of 127, 23 mantissa bits, with an implicit leading 1. Integers are exact up to 2242^{24}.

Part A: the basics (/70)

Exercise 1: Positional weights: reading a number in its base

In a base bb, the digit in position kk (counted from the right, starting at 0) has weight bkb^{k}. Converting to decimal means weighing: multiply each digit by the weight of its position and add. The grid below recalls the eight weights of a byte.

1286432168421bitsweights
  • a) Convert 10110110210110110_2 to decimal.
  • b) Convert 3578357_8 to decimal.
  • c) Convert 2F5162\text{F}5_{16} to decimal.
  • d) Convert 1101.10121101.101_2 to decimal.
  • e) What is the largest unsigned integer that can be represented on nn bits? On 8 bits? On 16 bits?

Type your answers, the page tells you right or wrong 0/12

a)
b)
c)
d)
e)
Show the solution

Answers

  • a) 182182
  • b) 239239
  • c) 757757
  • d) 13.62513.625
  • e) 2n−12^{n}-1, that is 255255 on 8 bits and 65 53565\,535 on 16 bits
a)

Write the weights above the bits: 128,64,32,16,8,4,2,1128, 64, 32, 16, 8, 4, 2, 1. The bits equal to 1 are those of weight 128128, 3232, 1616, 44 and 22. Sum: 128+32+16+4+2=182128+32+16+4+2 = 182. Quick check: the most significant bit is 1, so the number is at least 128; the least significant bit is 0, so the number is even. 182 satisfies both.

b)

In base 8, the weights are 64,8,164, 8, 1. So 3578=3(64)+5(8)+7(1)=192+40+7=239357_8 = 3(64) + 5(8) + 7(1) = 192 + 40 + 7 = 239. Check: the largest digit used is 7, which is allowed in base 8; an 8 or a 9 in an octal numeral would be a mistake in the question.

c)

In base 16, the weights are 256,16,1256, 16, 1, and F\text{F} stands for 15. So 2F516=2(256)+15(16)+5(1)=512+240+5=7572\text{F}5_{16} = 2(256) + 15(16) + 5(1) = 512 + 240 + 5 = 757. The letters A\text{A} to F\text{F} stand for 10 to 15: that is the only thing to memorize in hexadecimal.

d)

The integer part 110121101_2 is 8+4+1=138+4+1 = 13. After the binary point, the weights become negative powers: 2−1=0.52^{-1} = 0.5, then 2−2=0.252^{-2} = 0.25, then 2−3=0.1252^{-3} = 0.125. The bits are 1,0,11, 0, 1, so the fractional part is 0.5+0.125=0.6250.5 + 0.125 = 0.625. Total: 13.62513.625. The rule is the same on both sides of the point; only the sign of the exponent changes.

e)

On nn bits there are 2n2^{n} combinations, numbered from 0 to 2n−12^{n}-1: the largest unsigned integer is therefore 2n−12^{n}-1. On 8 bits, 255255; on 16 bits, 65 53565\,535. Classic pitfall: answering 2n2^{n} and forgetting that zero uses up one combination.

112806413211608141201bitsweights128 + 32 + 16 + 4 + 2 = 182

Tick the exercises you have done or want to review: a free account, no password, keeps your ticks and your right answers from one visit to the next, tells you which chapter to tackle next and lets you ask for the exercise you are missing. Create your space, an email is enough.

Exercise 2: From decimal to other bases: repeated division

To convert a decimal integer to base bb, divide repeatedly by bb and read the remainders from BOTTOM TO TOP. For a fractional part, multiply repeatedly by bb and read the integer parts from TOP TO BOTTOM. The two algorithms look alike, but the reading direction is reversed: that is where half the marks are lost.

  • a) Convert 156 to binary by repeated division and check with the weights.
  • b) Convert 156 to octal, then to hexadecimal.
  • c) Convert 0.68750.6875 to binary.
  • d) Try to convert 0.10.1 to binary. What happens?
  • e) Convert 1000 to hexadecimal.
  • f) What consequence does question d) have for a program that tests 0.1+0.2=0.30.1 + 0.2 = 0.3?

Type your answers, the page tells you right or wrong 0/14

a)
b)
c)
d)
e)
f)
Show the solution

Answers

  • a) 156=100111002156 = 10011100_2
  • b) 156=2348=9C16156 = 234_8 = 9\text{C}_{16}
  • c) 0.6875=0.101120.6875 = 0.1011_2
  • d) Repeating expansion: 0.1=0.00011‾20.1 = 0.0\overline{0011}_2, never terminating
  • e) 1000=3E8161000 = 3\text{E}8_{16}
  • f) Never compare two floats with strict equality: test ∣x−y∣<ε|x-y| < \varepsilon, and count money in cents, with integers
a)

156=2(78)+0156 = 2(78) + 0; 78=2(39)+078 = 2(39)+0; 39=2(19)+139 = 2(19)+1; 19=2(9)+119 = 2(9)+1; 9=2(4)+19 = 2(4)+1; 4=2(2)+04 = 2(2)+0; 2=2(1)+02 = 2(1)+0; 1=2(0)+11 = 2(0)+1. The remainders read from bottom to top give 10011100210011100_2. Check with the weights: 128+16+8+4=156128 + 16 + 8 + 4 = 156. The weight check is compulsory, because it catches the reading-direction error, which would give 0011100100111001.

b)

Dividing by 8: 156=8(19)+4156 = 8(19)+4; 19=8(2)+319 = 8(2)+3; 2=8(0)+22 = 8(0)+2, hence 2348234_8. Check: 2(64)+3(8)+4=128+24+4=1562(64)+3(8)+4 = 128+24+4 = 156. Dividing by 16: 156=16(9)+12156 = 16(9)+12; 9=16(0)+99 = 16(0)+9, and 12=C12 = \text{C}, hence 9C169\text{C}_{16}. Check: 9(16)+12=1569(16)+12 = 156. Shortcut: 10011100210011100_2 splits into 1001 1100=9C1001\ 1100 = 9\text{C}, in groups of 4 bits starting from the right.

c)

0.6875×2=1.3750.6875 \times 2 = 1.375, keep 1; 0.375×2=0.750.375 \times 2 = 0.75, keep 0; 0.75×2=1.50.75 \times 2 = 1.5, keep 1; 0.5×2=1.00.5 \times 2 = 1.0, keep 1, and nothing is left. Reading from top to bottom: 0.101120.1011_2. Check: 0.5+0.125+0.0625=0.68750.5 + 0.125 + 0.0625 = 0.6875. The conversion stops here because 0.6875=11160.6875 = \dfrac{11}{16} has a denominator that is a power of 2.

d)

0.1×2=0.20.1 \times 2 = 0.2; 0.2×2=0.40.2 \times 2 = 0.4; 0.4×2=0.80.4 \times 2 = 0.8; 0.8×2=1.60.8 \times 2 = 1.6; 0.6×2=1.20.6 \times 2 = 1.2; 0.2×2=0.40.2 \times 2 = 0.4, and we are back to a state already seen. The expansion is repeating: 0.1=0.00011‾20.1 = 0.0\overline{0011}_2, with no end. The reason is arithmetic: 0.1=1100.1 = \dfrac{1}{10} and 10 contains the factor 5, which is not a power of 2. A terminating decimal has a terminating binary expansion only if its reduced denominator is a power of 2.

e)

1000=16(62)+81000 = 16(62)+8; 62=16(3)+1462 = 16(3)+14, and 14=E14 = \text{E}; 3=16(0)+33 = 16(0)+3. Hence 3E8163\text{E}8_{16}. Check: 3(256)+14(16)+8=768+224+8=10003(256) + 14(16) + 8 = 768 + 224 + 8 = 1000.

f)

The computer does not store 0.10.1 but its infinite binary expansion rounded to the number of bits available. Three separate roundings occur, for 0.10.1, for 0.20.2 and for 0.30.3, and nothing guarantees that the sum of the first two lands exactly on the third: in practice it does not. The conclusion fits in one rule: never compare two floating-point numbers with strict equality; test ∣x−y∣<ε|x-y| < \varepsilon instead. For money, work in cents with integers.

Exercise 3: Binary arithmetic: adding, subtracting, multiplying

The four operations are worked in binary exactly as in decimal, with a tiny addition table: 0+0=00+0=0, 0+1=10+1=1, 1+1=101+1=10, 1+1+1=111+1+1=11. The carry propagates the same way. Every result must be checked in decimal, without exception.

  • a) Set up and compute 101102+1101210110_2 + 1101_2.
  • b) Set up and compute 1101012−101102110101_2 - 10110_2.
  • c) Set up and compute 10112×10121011_2 \times 101_2.
  • d) Carry out the division 11012÷1021101_2 \div 10_2 and give the quotient and the remainder.
  • e) What happens to a binary number when a 0 is appended on the right? Three zeros?

Type your answers, the page tells you right or wrong 0/12

a)
b)
c)
d)
e)
Show the solution

Answers

  • a) 1000112=35100011_2 = 35
  • b) 111112=3111111_2 = 31
  • c) 1101112=55110111_2 = 55
  • d) Quotient 1102=6110_2 = 6, remainder 11
  • e) One zero multiplies by 2, three zeros by 23=82^{3}=8
a)

Align on the right: 1011010110 is 22 and 11011101 is 13. Column by column from the right: 0+1=10+1 = 1; 1+0=11+0 = 1; 1+1=101+1 = 10, write 0 and carry 1; 0+1+1=100+1+1 = 10, write 0 and carry 1; 1+0+1=101+0+1 = 10, write 0 and carry 1; the carry remains, write 1. Result: 1000112100011_2. Check: 32+2+1=3532+2+1 = 35 and 22+13=3522+13 = 35.

b)

110101110101 is 53 and 1011010110 is 22. Borrow as in decimal, a borrow being worth 2 in the column that receives it. From the right: 1−0=11-0 = 1; 0−10-1 forces a borrow, 10−1=110-1 = 1; then 1−11-1 minus the borrow forces another borrow, 11−1−1=111-1-1 = 1; then 0−00-0 minus the borrow borrows again, 10−0−1=110-0-1 = 1; then 11−1−1=111-1-1 = 1 once more; finally 1−0−1=01-0-1 = 0. Result: 11111211111_2. Check: 16+8+4+2+1=3116+8+4+2+1 = 31 and 53−22=3153-22 = 31. A result of 1111111111 is not suspicious: it is 25−12^{5}-1.

c)

10111011 is 11 and 101101 is 5. Binary multiplication needs no table: each bit of the multiplier gives either a shifted copy of the multiplicand or a row of zeros. Here: 10111011 (bit of weight 1), 000000000000 (bit of weight 2, zero), 101100101100 (bit of weight 4, so shifted two positions). Sum: 1011+101100=11011121011 + 101100 = 110111_2. Check: 32+16+4+2+1=5532+16+4+2+1 = 55 and 11×5=5511 \times 5 = 55.

d)

11011101 is 13 and 1010 is 2. Dividing by 10210_2 means shifting one position to the right: the quotient is 1102=6110_2 = 6 and the bit pushed out, here 1, is the remainder. Check: 2(6)+1=132(6)+1 = 13. Dividing by a power of 2 is a shift, which explains why compilers replace n/2n/2 with a shift when nn is an unsigned integer.

e)

Appending a 0 on the right shifts every bit one position to the left: each bit sees its weight doubled, so the number is multiplied by 2, not by 10. Three zeros multiply by 23=82^{3} = 8. It is the same mechanism as in decimal, where appending a zero multiplies by 10, that is, by the base. Remember: the factor is always the base, never ten.

Exercise 4: Two's complement: representing negative numbers

On nn bits, two's complement represents negative numbers without a separate sign: −x-x is written as the pattern of 2n−x2^{n}-x. The most significant bit then acts as a sign indicator, and ordinary addition keeps working without any change to the circuit. The wheel below shows the 16 patterns of 4 bits: moving one step forward adds 1, and you go past the top with no break.

00000000110010200113010040101501106011171000−81001−71010−61011−51100−41101−31110−21111−1one step = +1outside: the 4 bits inside: the signed value
  • a) Write −37-37 in two's complement on 8 bits, showing both steps.
  • b) The pattern 1011010010110100 is read as a signed integer on 8 bits. What is its value?
  • c) What is the range of signed integers on 8 bits? Why is it not symmetric?
  • d) Compute 45−3745 - 37 using only an addition on 8 bits.
  • e) On 4 bits, what is the opposite of −8-8? What does this case reveal?

Type your answers, the page tells you right or wrong 0/13

a)
b)
c)
d)
e)
Show the solution

Answers

  • a) −37=110110112=DB16-37 = 11011011_2 = \text{DB}_{16}, whose unsigned reading is 219=256−37219 = 256-37
  • b) −76-76
  • c) From −128-128 to +127+127: zero takes up a pattern on the positive side
  • d) 45+110110112=845 + 11011011_2 = 8, the carry out being discarded
  • e) The opposite of −8-8 is −8-8: negation is not total
a)

Step 1: write 3737 on 8 bits. 37=32+4+137 = 32+4+1, so 0010010100100101. Step 2: invert all the bits, which gives 1101101011011010, then add 1: 1101101111011011. Numerical check: 1101101111011011 is 128+64+16+8+2+1=219128+64+16+8+2+1 = 219, and 219=256−37219 = 256 - 37, which is exactly the definition. In hexadecimal, DB\text{DB}.

b)

The most significant bit is 1, so the number is negative. Two methods. Direct method: read the pattern as unsigned, 10110100=128+32+16+4=18010110100 = 128+32+16+4 = 180, then subtract 256256: 180−256=−76180 - 256 = -76. Complement method: invert, 0100101101001011, add 1, 01001100=64+8+4=7601001100 = 64+8+4 = 76, so the pattern stood for −76-76. Both give the same result, and that is the check to do.

c)

From −128-128 to +127+127. There are 256256 patterns; half of them, those whose most significant bit is 0, encode 00 to 127127; the other half encode −128-128 to −1-1. The asymmetry comes from zero taking up a slot on the positive side: 127127 patterns remain for the positive numbers and 128128 for the negative ones. That is precisely the advantage of two's complement over representations with a separate sign bit, which have two zeros and waste a pattern.

d)

45=0010110145 = 00101101. Add to it the representation of −37-37, namely 1101101111011011. Binary addition gives 1 000010001\,00001000 over nine columns: the carry out of position 8 is simply discarded, and what remains is 00001000=800001000 = 8. Check: 45−37=845-37 = 8. That is the whole point of two's complement: the adder circuit also serves as the subtractor, give or take an inverter.

e)

On 4 bits, the range is −8-8 to +7+7. The opposite of −8-8 should be +8+8, which does not exist in the range. Applying the recipe: −8-8 is written 10001000; invert, 01110111; add 1, 10001000: we land back on −8-8. The case reveals that negation in two's complement is not total, and it is a real programming trap, where ∣x∣\lvert x \rvert can return a negative number for the lower bound of the range.

Exercise 5: Base 8 lab: from expanded notation to long multiplication

Octal has only eight digits, from 0 to 7, and each position has a power of 8 as its weight. Everything you can do in base 10 can be redone in base 8 with a single change: you carry as soon as you reach 8, and you borrow 8, not 10. This exercise goes through the complete route of the binary arithmetic lab, in octal: writing a number in expanded notation, converting it both ways, adding, subtracting, multiplying, then closing the loop with a round trip checked in decimal. Every result is checked by going back through decimal, and that check is what makes the difference between a correct calculation and one that only looks correct.

Tables to know or to rebuild on scrap paper: 81=88^{1} = 8, 82=648^{2} = 64, 83=5128^{3} = 512, 84=40968^{4} = 4096, and the reciprocals 8−1=0.1258^{-1} = 0.125, 8−2=0.0156258^{-2} = 0.015625.

  • a) Write 2471.3582471.35_8 in expanded notation, as a sum of products of its digits by decreasing powers of 8, then give its decimal value.
  • b) Convert to decimal: 7358735_8, 120481204_8, 61.4861.4_8 and 0.5280.52_8.
  • c) Convert to octal: 200200, 10001000, 93.7593.75 and 0.10.1. What happens for the last one?
  • d) Set up and compute the octal additions 3578+2468357_8 + 246_8, 17458+6338+2781745_8 + 633_8 + 27_8 and 12.568+7.37812.56_8 + 7.37_8.
  • e) We work with 4 octal digits. Define the 7's complement and the 8's complement of a number, compute the 8's complement of 032580325_8, then use it to carry out 24618−032582461_8 - 0325_8 by an addition. What is the range of signed integers on 4 octal digits, and how do you recognize a negative number?
  • f) Set up and compute the octal subtractions 70428−356787042_8 - 3567_8 and 10.28−3.75810.2_8 - 3.75_8, showing the borrows.
  • g) Set up and compute the octal multiplications 538×7853_8 \times 7_8, 1248×358124_8 \times 35_8 and 6.48×2.286.4_8 \times 2.2_8.
  • h) Convert both numbers to octal, carry out the operation in octal, then go back to decimal to check: 345+219345 + 219 and 6.5×3.256.5 \times 3.25.
  • i) On Linux, the command chmod 755 sets the permissions of a file. Write 7558755_8 in binary and explain what each octal digit represents. Why is octal the natural base for this encoding?

Type your answers, the page tells you right or wrong 0/32

a)
b)
c)
d)
e)
f)
g)
h)
i)
Show the solution

Answers

  • a) 2⋅83+4⋅82+7⋅8+1+3⋅8−1+5⋅8−2=1337.4531252\cdot 8^{3}+4\cdot 8^{2}+7\cdot 8+1+3\cdot 8^{-1}+5\cdot 8^{-2} = 1337.453125
  • b) 477477, 644644, 49.549.5 and 0.656250.65625
  • c) 3108310_8, 175081750_8, 135.68135.6_8; 0.1=0.06314‾80.1 = 0.0\overline{6314}_8, repeating
  • d) 6258625_8, 262782627_8 and 22.15822.15_8
  • e) 8's complement of 032580325_8: 745387453_8; 24618−03258=213482461_8-0325_8 = 2134_8; range −2048-2048 to 20472047, negative as soon as the leading digit reaches 4
  • f) 325383253_8 and 4.2384.23_8
  • g) 4558455_8, 460484604_8 and 16.5816.5_8
  • h) 5318+3338=10648=564531_8+333_8 = 1064_8 = 564; 6.48×3.28=25.18=21.1256.4_8 \times 3.2_8 = 25.1_8 = 21.125
  • i) 7558=111 101 1012755_8 = 111\ 101\ 101_2: three parties, three bits each, read, write, execute
a)

The radix point separates the positive positions from the negative ones. On the left, moving left from the point, the weights are 80,81,82,838^{0}, 8^{1}, 8^{2}, 8^{3}; on the right, 8−18^{-1} then 8−28^{-2}. Hence 2471.358=2⋅83+4⋅82+7⋅81+1⋅80+3⋅8−1+5⋅8−22471.35_8 = 2 \cdot 8^{3} + 4 \cdot 8^{2} + 7 \cdot 8^{1} + 1 \cdot 8^{0} + 3 \cdot 8^{-1} + 5 \cdot 8^{-2}. Value: 2(512)+4(64)+7(8)+1+38+564=1024+256+56+1+0.375+0.078125=1337.4531252(512) + 4(64) + 7(8) + 1 + \dfrac{3}{8} + \dfrac{5}{64} = 1024 + 256 + 56 + 1 + 0.375 + 0.078125 = 1337.453125. Expanded notation is not an exercise in style: it is the very definition of the base, and every conversion to decimal is just this calculation written faster.

b)

7358=7(64)+3(8)+5=448+24+5=477735_8 = 7(64) + 3(8) + 5 = 448 + 24 + 5 = 477. 12048=1(512)+2(64)+0(8)+4=512+128+4=6441204_8 = 1(512) + 2(64) + 0(8) + 4 = 512 + 128 + 4 = 644: the zero is weighed too; it holds a position even though it adds nothing. 61.48=6(8)+1+48=49.561.4_8 = 6(8) + 1 + \dfrac{4}{8} = 49.5. 0.528=58+264=0.625+0.03125=0.656250.52_8 = \dfrac{5}{8} + \dfrac{2}{64} = 0.625 + 0.03125 = 0.65625. Classic pitfall: reading 0.5280.52_8 as fifty-two hundredths. In base 8, the second digit after the point is worth one sixty-fourth, not one hundredth.

c)

Integer part by repeated division by 8, remainders read from bottom to top. 200=8(25)+0200 = 8(25) + 0; 25=8(3)+125 = 8(3) + 1; 3=8(0)+33 = 8(0) + 3, hence 200=3108200 = 310_8; check 3(64)+1(8)=2003(64) + 1(8) = 200. 1000=8(125)+01000 = 8(125) + 0; 125=8(15)+5125 = 8(15) + 5; 15=8(1)+715 = 8(1) + 7; 1=8(0)+11 = 8(0) + 1, hence 1000=175081000 = 1750_8; check 512+7(64)+5(8)=512+448+40=1000512 + 7(64) + 5(8) = 512 + 448 + 40 = 1000. For 93.7593.75, split it: 93=8(11)+593 = 8(11) + 5; 11=8(1)+311 = 8(1) + 3; 1=8(0)+11 = 8(0) + 1, so 93=135893 = 135_8; then 0.75×8=6.00.75 \times 8 = 6.0, keep 6 and nothing is left, so 93.75=135.6893.75 = 135.6_8. Check: 64+24+5+0.75=93.7564 + 24 + 5 + 0.75 = 93.75. For 0.10.1: 0.1×8=0.80.1 \times 8 = 0.8, digit 0; 0.8×8=6.40.8 \times 8 = 6.4, digit 6; 0.4×8=3.20.4 \times 8 = 3.2, digit 3; 0.2×8=1.60.2 \times 8 = 1.6, digit 1; 0.6×8=4.80.6 \times 8 = 4.8, digit 4; 0.8×8=6.40.8 \times 8 = 6.4, and we are back to a state already seen. The expansion is repeating: 0.1=0.06314‾80.1 = 0.0\overline{6314}_8. No surprise: 0.1=1100.1 = \dfrac{1}{10} and 10 contains the factor 5, which divides no power of 8. A terminating decimal has a terminating expansion in base 8 exactly when its reduced denominator is a power of 2, the same condition as in binary, because 8=238 = 2^{3}.

d)

Add column by column, and as soon as a column reaches 8, write the remainder and carry 1. First addition: ones 7+6=13=8+57 + 6 = 13 = 8 + 5, write 5 and carry 1; eights 5+4+1=10=8+25 + 4 + 1 = 10 = 8 + 2, write 2 and carry 1; 3+2+1=63 + 2 + 1 = 6. Result 6258625_8. Decimal check: 3578=239357_8 = 239, 2468=166246_8 = 166, sum 405, and 6258=6(64)+2(8)+5=405625_8 = 6(64) + 2(8) + 5 = 405. Second addition, with three terms aligned on the right: ones 5+3+7=15=8+75 + 3 + 7 = 15 = 8 + 7, write 7 and carry 1; 4+3+2+1=104 + 3 + 2 + 1 = 10, write 2, carry 1; 7+6+0+1=147 + 6 + 0 + 1 = 14, write 6, carry 1; 1+0+0+1=21 + 0 + 0 + 1 = 2. Result 262782627_8. Check: 997+411+23=1431997 + 411 + 23 = 1431 and 26278=2(512)+6(64)+2(8)+7=14312627_8 = 2(512) + 6(64) + 2(8) + 7 = 1431. Third addition, with radix points, lining up the points: 6+7=136 + 7 = 13, write 5, carry 1; 5+3+1=95 + 3 + 1 = 9, write 1, carry 1; 2+7+1=102 + 7 + 1 = 10, write 2, carry 1; 1+0+1=21 + 0 + 1 = 2. Result 22.15822.15_8. Check: 10.71875+7.484375=18.20312510.71875 + 7.484375 = 18.203125 and 22.158=18+18+564=18.20312522.15_8 = 18 + \dfrac{1}{8} + \dfrac{5}{64} = 18.203125. The most frequent error is carrying at 10 out of habit: 7+67 + 6 is then written down as 13, and the result is off by 8 in that column.

e)

The 7's complement of a 4-digit octal number is obtained by replacing each digit dd with 7−d7 - d, with no carry at all; it is the analogue of inverting the bits. The 8's complement is the 7's complement plus 1, and it equals 84−x=4096−x8^{4} - x = 4096 - x: it is the analogue of two's complement. For 032580325_8: 7's complement, digit by digit, 7−0,7−3,7−2,7−57-0, 7-3, 7-2, 7-5, that is 745287452_8; plus 1, 745387453_8. Check: 03258=3(64)+2(8)+5=2130325_8 = 3(64) + 2(8) + 5 = 213, 4096−213=38834096 - 213 = 3883, and 74538=7(512)+4(64)+5(8)+3=3584+256+40+3=38837453_8 = 7(512) + 4(64) + 5(8) + 3 = 3584 + 256 + 40 + 3 = 3883. Subtraction by addition: 24618+745382461_8 + 7453_8. Ones 1+3=41 + 3 = 4; 6+5=11=8+36 + 5 = 11 = 8 + 3, write 3, carry 1; 4+4+1=94 + 4 + 1 = 9, write 1, carry 1; 2+7+1=102 + 7 + 1 = 10, write 2, carry 1. We get 12134812134_8 on five digits; the carry that comes out on the left is discarded, since we work with 4 digits, and what remains is 213482134_8. Check: 24618=13292461_8 = 1329, 1329−213=11161329 - 213 = 1116, and 21348=1024+64+24+4=11162134_8 = 1024 + 64 + 24 + 4 = 1116. Why it works: adding 4096−x4096 - x and then discarding 40964096 is exactly the same as subtracting xx. Signed range on 4 octal digits, that is, 12 bits: from −211=−2048-2^{11} = -2048 to 211−1=20472^{11} - 1 = 2047, that is, from 400084000_8 (read as −2048-2048) to 377783777_8. A number is negative when its leading digit is 4 or more: the upper half of the patterns represents the negative numbers, exactly like the most significant bit in binary, since the first octal digit contains that bit. So 745387453_8, read as a signed integer, is 3883−4096=−2133883 - 4096 = -213.

f)

First subtraction, 70428−356787042_8 - 3567_8. Ones: 2<72 < 7, borrow one eight, 2+8−7=32 + 8 - 7 = 3, and the eights digit goes from 4 to 3. Eights: 3<63 < 6, borrow, 3+8−6=53 + 8 - 6 = 5, and the 64s digit must go down by 1; it is 0, so first borrow from the 512s, which go from 7 to 6, and the 64s become 8−1=78 - 1 = 7. 64s column: 7−5=27 - 5 = 2. 512s column: 6−3=36 - 3 = 3. Result 325383253_8. Check: 70428=36187042_8 = 3618, 35678=19113567_8 = 1911, difference 1707, and 32538=3(512)+2(64)+5(8)+3=17073253_8 = 3(512) + 2(64) + 5(8) + 3 = 1707. Second subtraction, 10.208−3.75810.20_8 - 3.75_8, padding 10.210.2 with a zero to line up: sixty-fourths 0<50 < 5, borrow, 0+8−5=30 + 8 - 5 = 3, and the eighths go from 2 to 1; eighths 1<71 < 7, borrow, 1+8−7=21 + 8 - 7 = 2, and the ones, which are 0, borrow from the eights, 1→01 \to 0, to become 8−1=78 - 1 = 7; ones 7−3=47 - 3 = 4; eights 0−0=00 - 0 = 0. Result 4.2384.23_8. Check: 8.25−3.953125=4.2968758.25 - 3.953125 = 4.296875 and 4.238=4+28+364=4.2968754.23_8 = 4 + \dfrac{2}{8} + \dfrac{3}{64} = 4.296875. The trap of a cascading borrow through a zero is the same as in decimal; the only novelty is that a borrow is worth 8.

g)

Long multiplication, with the 8 times table in mind: each partial product is reduced modulo 8 and the carry can exceed 1. 538×7853_8 \times 7_8: 3×7=21=2(8)+53 \times 7 = 21 = 2(8) + 5, write 5 and carry 2; 5×7+2=37=4(8)+55 \times 7 + 2 = 37 = 4(8) + 5, write 5 then 4. Result 4558455_8; check 43×7=301=4(64)+5(8)+543 \times 7 = 301 = 4(64) + 5(8) + 5. 1248×358124_8 \times 35_8: by 5, 4×5=20=2(8)+44 \times 5 = 20 = 2(8) + 4, write 4, carry 2; 2×5+2=12=8+42 \times 5 + 2 = 12 = 8 + 4, write 4, carry 1; 1×5+1=61 \times 5 + 1 = 6, row 6448644_8. By 3, shifted one position: 4×3=124 \times 3 = 12, write 4, carry 1; 2×3+1=72 \times 3 + 1 = 7; 1×3=31 \times 3 = 3, row 374083740_8. Sum 6448+37408644_8 + 3740_8: 4+0=44 + 0 = 4; 4+4=84 + 4 = 8, write 0, carry 1; 6+7+1=146 + 7 + 1 = 14, write 6, carry 1; 3+1=43 + 1 = 4. Result 460484604_8; check 84×29=2436=4(512)+6(64)+484 \times 29 = 2436 = 4(512) + 6(64) + 4. 6.48×2.286.4_8 \times 2.2_8: multiply without the points, 648×22864_8 \times 22_8, and then put back as many digits after the point as there were in total in the factors, here 1+1=21 + 1 = 2. 648×2=150864_8 \times 2 = 150_8 (since 4×2=84 \times 2 = 8, write 0, carry 1; 6×2+1=136 \times 2 + 1 = 13, write 5, carry 1); the row for the other 2, shifted, gives 150081500_8; sum 165081650_8; with two fractional digits, 16.508=16.5816.50_8 = 16.5_8. Check: 6.5×2.25=14.6256.5 \times 2.25 = 14.625 and 16.58=14+58=14.62516.5_8 = 14 + \dfrac{5}{8} = 14.625. The rule for placing the point is the same as in decimal, because it depends only on the number of positions, not on the base.

h)

345=8(43)+1345 = 8(43) + 1, 43=8(5)+343 = 8(5) + 3, 5=8(0)+55 = 8(0) + 5, so 345=5318345 = 531_8; 219=8(27)+3219 = 8(27) + 3, 27=8(3)+327 = 8(3) + 3, so 219=3338219 = 333_8. Addition: 1+3=41 + 3 = 4; 3+3=63 + 3 = 6; 5+3=85 + 3 = 8, write 0, carry 1, and write 1 in front. Result 106481064_8, and back: 512+6(8)+4=564=345+219512 + 6(8) + 4 = 564 = 345 + 219. The check closes the loop. Then 6.5=6.486.5 = 6.4_8 since 0.5=480.5 = \dfrac{4}{8}, and 3.25=3.283.25 = 3.2_8 since 0.25=280.25 = \dfrac{2}{8}. Compute 648×32864_8 \times 32_8: by 2, 1508150_8; by 3, shifted: 4×3=12=8+44 \times 3 = 12 = 8 + 4, write 4 and carry 1; 6×3+1=19=2(8)+36 \times 3 + 1 = 19 = 2(8) + 3, write 3 then 2, which gives 2348234_8, then 234082340_8; sum 1508+23408=25108150_8 + 2340_8 = 2510_8; two fractional digits: 25.108=25.1825.10_8 = 25.1_8. Back: 2(8)+5+18=21.1252(8) + 5 + \dfrac{1}{8} = 21.125, and 6.5×3.25=21.1256.5 \times 3.25 = 21.125. Both numbers have terminating octal expansions because their fractional parts, 12\dfrac{1}{2} and 14\dfrac{1}{4}, have a power of 2 as denominator.

i)

Each octal digit is exactly 3 bits: 7=11127 = 111_2, 5=10125 = 101_2, so 7558=111 101 1012755_8 = 111\ 101\ 101_2. The three digits encode the permissions of three parties, the owner, the group and others, and the three bits of each digit are, in order, read, write, execute. 7=1117 = 111: the owner can do everything; 5=1015 = 101: the group and others can read and execute, not write. Base 8 is natural here because permissions come in groups of 3 bits and an octal digit is precisely a group of 3 bits: the split needs no calculation, it is simply read off. A 644, for comparison, gives 110 100 100110\ 100\ 100: the owner reads and writes, the others only read. That is why the binary to octal conversion works in groups of 3, and why octal survives wherever bits are handled in triples.

Exercise 6: Base 16 lab: from expanded notation to long multiplication

Hexadecimal has sixteen digits: 0 to 9, then A, B, C, D, E, F for 10 to 15. Each position has a power of 16 as its weight; you carry as soon as you reach 16, and you borrow 16. It is the base of everything displayed in computing, memory addresses, colours, the bytes of a file, because one hexadecimal digit is exactly 4 bits and a byte fits in two digits. This exercise goes through the complete route of the lab again in base 16: expanded notation, conversions both ways, addition, complement, subtraction, multiplication, and a checked round trip.

Tables to keep at hand: 162=25616^{2} = 256, 163=409616^{3} = 4096, 164=6553616^{4} = 65536, 16−1=0.062516^{-1} = 0.0625, 16−2=0.0039062516^{-2} = 0.00390625; the product of two hexadecimal digits is rebuilt in decimal and then reduced modulo 16.

  • a) Write 3AF.C8163\text{AF}.\text{C}8_{16} in expanded notation, then give its decimal value.
  • b) Convert to decimal: 2B162\text{B}_{16}, 7D0167\text{D}0_{16}, FFFF16\text{FFFF}_{16}, A.416\text{A}.4_{16} and 0.18160.18_{16}.
  • c) Convert to hexadecimal: 255255, 40964096, 30003000, 0.81250.8125 and 0.10.1. What do you notice for the last one?
  • d) Set up and compute the hexadecimal additions 3C16+2F163\text{C}_{16} + 2\text{F}_{16}, A9F16+7E516\text{A}9\text{F}_{16} + 7\text{E}5_{16} and 1F.816+C.A161\text{F}.8_{16} + \text{C}.\text{A}_{16}.
  • e) We work with 4 hexadecimal digits. Define the 15's complement and the 16's complement, compute the 16's complement of 02D41602\text{D}4_{16}, then use it to carry out 1A7B16−02D4161\text{A}7\text{B}_{16} - 02\text{D}4_{16} by an addition. How is this related to two's complement on 16 bits, and how do you recognize a negative number?
  • f) Set up and compute the hexadecimal subtractions B0516−4C916\text{B}05_{16} - 4\text{C}9_{16} and 10.416−7.C1610.4_{16} - 7.\text{C}_{16}, showing the borrows.
  • g) Set up and compute the hexadecimal multiplications 2A16×B162\text{A}_{16} \times \text{B}_{16}, 1F16×3C161\text{F}_{16} \times 3\text{C}_{16} and 4.816×2.4164.8_{16} \times 2.4_{16}.
  • h) Convert both numbers to hexadecimal, carry out the operation in hexadecimal, then go back to decimal to check: 1000−2551000 - 255 and 12.75×2.512.75 \times 2.5.

Type your answers, the page tells you right or wrong 0/33

a)
b)
c)
d)
e)
f)
g)
h)
Show the solution

Answers

  • a) 3⋅162+10⋅16+15+12⋅16−1+8⋅16−2=943.781253\cdot 16^{2}+10\cdot 16+15+12\cdot 16^{-1}+8\cdot 16^{-2} = 943.78125
  • b) 4343, 20002000, 65 53565\,535, 10.2510.25 and 0.093750.09375
  • c) FF16\text{FF}_{16}, 1000161000_{16}, BB816\text{BB}8_{16}, 0.D160.\text{D}_{16}; 0.1=0.19‾160.1 = 0.1\overline{9}_{16}, repeating
  • d) 6B166\text{B}_{16}, 1284161284_{16} and 2C.2162\text{C}.2_{16}
  • e) 16's complement of 02D41602\text{D}4_{16}: FD2C16\text{FD}2\text{C}_{16}; the difference is 17A716=605517\text{A}7_{16} = 6055; range −32 768-32\,768 to 32 76732\,767, negative as soon as the leading digit reaches 8
  • f) 63C1663\text{C}_{16} and 8.8168.8_{16}
  • g) 1CE161\text{CE}_{16}, 74416744_{16} and A.216\text{A}.2_{16}
  • h) 2E916=7452\text{E}9_{16} = 745 and 1F.E16=31.8751\text{F}.\text{E}_{16} = 31.875
a)

The weights, moving left from the radix point, are 160,161,16216^{0}, 16^{1}, 16^{2}; moving right, 16−1,16−216^{-1}, 16^{-2}. Hence 3AF.C816=3⋅162+10⋅161+15⋅160+12⋅16−1+8⋅16−23\text{AF}.\text{C}8_{16} = 3 \cdot 16^{2} + 10 \cdot 16^{1} + 15 \cdot 16^{0} + 12 \cdot 16^{-1} + 8 \cdot 16^{-2}, replacing A, F and C by their values 10, 15 and 12. Value: 3(256)+10(16)+15+1216+8256=768+160+15+0.75+0.03125=943.781253(256) + 10(16) + 15 + \dfrac{12}{16} + \dfrac{8}{256} = 768 + 160 + 15 + 0.75 + 0.03125 = 943.78125. The only new difficulty compared with octal is remembering that A is 10, not 1, and that F is 15, not 6.

b)

2B16=2(16)+11=432\text{B}_{16} = 2(16) + 11 = 43. 7D016=7(256)+13(16)+0=1792+208=20007\text{D}0_{16} = 7(256) + 13(16) + 0 = 1792 + 208 = 2000. FFFF16=15(4096)+15(256)+15(16)+15=61440+3840+240+15=65535\text{FFFF}_{16} = 15(4096) + 15(256) + 15(16) + 15 = 61440 + 3840 + 240 + 15 = 65535, and faster: four digits all at their maximum are worth 164−1=6553516^{4} - 1 = 65535, the largest integer on 16 bits. A.416=10+416=10.25\text{A}.4_{16} = 10 + \dfrac{4}{16} = 10.25. 0.1816=116+8256=0.0625+0.03125=0.093750.18_{16} = \dfrac{1}{16} + \dfrac{8}{256} = 0.0625 + 0.03125 = 0.09375. Same pitfall as in octal: 0.18160.18_{16} has nothing to do with eighteen hundredths; the second digit is worth one two-hundred-fifty-sixth.

c)

255=16(15)+15255 = 16(15) + 15, 15=16(0)+1515 = 16(0) + 15, two remainders of 15, that is FF16\text{FF}_{16}; check 15(16)+15=25515(16) + 15 = 255, the full byte. 4096=1634096 = 16^{3}, so 1000161000_{16}: a 1 followed by three zeros, like 1000=1031000 = 10^{3} in decimal. 3000=16(187)+83000 = 16(187) + 8; 187=16(11)+11187 = 16(11) + 11; 11=16(0)+1111 = 16(0) + 11; remainders read from bottom to top, 11,11,811, 11, 8, that is BB816\text{BB}8_{16}; check 11(256)+11(16)+8=2816+176+8=300011(256) + 11(16) + 8 = 2816 + 176 + 8 = 3000. 0.8125×16=13.00.8125 \times 16 = 13.0, digit D, and nothing is left: 0.8125=0.D160.8125 = 0.\text{D}_{16}, which is consistent with 0.8125=13160.8125 = \dfrac{13}{16}. For 0.10.1: 0.1×16=1.60.1 \times 16 = 1.6, digit 1; 0.6×16=9.60.6 \times 16 = 9.6, digit 9; 0.6×16=9.60.6 \times 16 = 9.6, digit 9, and so on. So 0.1=0.19‾160.1 = 0.1\overline{9}_{16}, repeating. It is the same impossibility as in binary and in octal, for the same reason: 16=2416 = 2^{4}, so a decimal has a terminating expansion in base 16 if and only if it has one in base 2, that is, if its reduced denominator is a power of 2. One tenth, with its factor 5, will never qualify. You can in fact read the binary 0.00011‾20.0\overline{0011}_2 through the hexadecimal: 1=00011 = 0001, 9=10019 = 1001, and the concatenation 0001 1001 1001…0001\ 1001\ 1001\dots does give back the pattern 00110011 repeated, shifted by one position.

d)

3C16+2F163\text{C}_{16} + 2\text{F}_{16}: ones C+F=12+15=27=16+11\text{C} + \text{F} = 12 + 15 = 27 = 16 + 11, write B and carry 1; 3+2+1=63 + 2 + 1 = 6. Result 6B166\text{B}_{16}; check 60+47=107=6(16)+1160 + 47 = 107 = 6(16) + 11. A9F16+7E516\text{A}9\text{F}_{16} + 7\text{E}5_{16}: F+5=20=16+4\text{F} + 5 = 20 = 16 + 4, write 4, carry 1; 9+E+1=9+14+1=24=16+89 + \text{E} + 1 = 9 + 14 + 1 = 24 = 16 + 8, write 8, carry 1; A+7+1=18=16+2\text{A} + 7 + 1 = 18 = 16 + 2, write 2, carry 1, written in front. Result 1284161284_{16}; check 2719+2021=4740=4096+2(256)+8(16)+42719 + 2021 = 4740 = 4096 + 2(256) + 8(16) + 4. 1F.816+C.A161\text{F}.8_{16} + \text{C}.\text{A}_{16}, radix points lined up: 8+A=18=16+28 + \text{A} = 18 = 16 + 2, write 2, carry 1; F+C+1=15+12+1=28=16+12\text{F} + \text{C} + 1 = 15 + 12 + 1 = 28 = 16 + 12, write C, carry 1; 1+0+1=21 + 0 + 1 = 2. Result 2C.2162\text{C}.2_{16}; check 31.5+12.625=44.125=2(16)+12+21631.5 + 12.625 = 44.125 = 2(16) + 12 + \dfrac{2}{16}. The safe method for each column: add in decimal, subtract 16 if you go past 15, then translate the remainder into a hexadecimal digit. The pitfall is writing 27 or 11 instead of B.

e)

The 15's complement of a 4-digit hexadecimal number replaces each digit dd with 15−d15 - d: it is bit inversion, since 15−d15 - d inverts the 4 bits of dd. The 16's complement adds 1 to the result and equals 164−x=65536−x16^{4} - x = 65536 - x. For 02D41602\text{D}4_{16}: 15's complement, F−0,F−2,F−D,F−4\text{F}-0, \text{F}-2, \text{F}-\text{D}, \text{F}-4, that is FD2B16\text{FD}2\text{B}_{16}; plus 1, FD2C16\text{FD}2\text{C}_{16}. Check: 02D416=2(256)+13(16)+4=72402\text{D}4_{16} = 2(256) + 13(16) + 4 = 724, 65536−724=6481265536 - 724 = 64812, and FD2C16=15(4096)+13(256)+2(16)+12=61440+3328+32+12=64812\text{FD}2\text{C}_{16} = 15(4096) + 13(256) + 2(16) + 12 = 61440 + 3328 + 32 + 12 = 64812. Subtraction by addition: 1A7B16+FD2C161\text{A}7\text{B}_{16} + \text{FD}2\text{C}_{16}. B+C=23=16+7\text{B} + \text{C} = 23 = 16 + 7, write 7, carry 1; 7+2+1=107 + 2 + 1 = 10, write A; A+D=23\text{A} + \text{D} = 23, write 7, carry 1; 1+F+1=17=16+11 + \text{F} + 1 = 17 = 16 + 1, write 1, carry 1. We get 117A716117\text{A}7_{16}; discard the carry out, and 17A71617\text{A}7_{16} remains. Check: 1A7B16=67791\text{A}7\text{B}_{16} = 6779, 6779−724=60556779 - 724 = 6055, and 17A716=4096+7(256)+10(16)+7=605517\text{A}7_{16} = 4096 + 7(256) + 10(16) + 7 = 6055. Link with two's complement: 4 hexadecimal digits are 16 bits, and FD2C16\text{FD}2\text{C}_{16} is exactly the pattern of −724-724 in two's complement on 16 bits; the 16's complement is not another operation, it is two's complement written in base 16, four bits at a time. Signed range: from 800016=−327688000_{16} = -32768 to 7FFF16=327677\text{FFF}_{16} = 32767. A number is negative when its leading digit is 8 or more, because that digit contains the most significant bit; so FD2C16\text{FD}2\text{C}_{16} read as signed is 64812−65536=−72464812 - 65536 = -724.

f)

B0516−4C916\text{B}05_{16} - 4\text{C}9_{16}. Ones: 5<95 < 9, borrow 16, 5+16−9=125 + 16 - 9 = 12, write C, and the sixteens digit must go down by 1; it is 0, so borrow from the 256s, B becomes A, and the sixteens become 16−1=15=F16 - 1 = 15 = \text{F}. Sixteens: F−C=15−12=3\text{F} - \text{C} = 15 - 12 = 3. 256s column: A−4=6\text{A} - 4 = 6. Result 63C1663\text{C}_{16}. Check: B0516=2821\text{B}05_{16} = 2821, 4C916=12254\text{C}9_{16} = 1225, difference 1596, and 63C16=6(256)+3(16)+12=159663\text{C}_{16} = 6(256) + 3(16) + 12 = 1596. 10.416−7.C1610.4_{16} - 7.\text{C}_{16}: sixteenths 4<C4 < \text{C}, borrow, 4+16−12=84 + 16 - 12 = 8, and the ones, which are 0, borrow from the 1 on the left to become F; ones F−7=8\text{F} - 7 = 8; the leading 1 has become 0. Result 8.8168.8_{16}. Check: 16.25−7.75=8.5=8+81616.25 - 7.75 = 8.5 = 8 + \dfrac{8}{16}. A borrow is worth 16, and a cascading borrow through a zero leaves an F behind it, as it leaves a 9 in decimal and a 7 in octal.

g)

2A16×B162\text{A}_{16} \times \text{B}_{16}: A×B=10×11=110=6(16)+14\text{A} \times \text{B} = 10 \times 11 = 110 = 6(16) + 14, write E and carry 6; 2×B+6=28=16+122 \times \text{B} + 6 = 28 = 16 + 12, write C, carry 1, written in front. Result 1CE161\text{CE}_{16}; check 42×11=462=256+12(16)+1442 \times 11 = 462 = 256 + 12(16) + 14. Note the carry of 6: in base 16, a multiplication carry can go up to 14, which throws off anyone who only ever carries 1 out of habit. 1F16×3C161\text{F}_{16} \times 3\text{C}_{16}: by C, F×C=180=11(16)+4\text{F} \times \text{C} = 180 = 11(16) + 4, write 4, carry 11; 1×C+11=23=16+71 \times \text{C} + 11 = 23 = 16 + 7, write 7, carry 1, row 17416174_{16}. By 3, shifted: F×3=45=2(16)+13\text{F} \times 3 = 45 = 2(16) + 13, write D, carry 2; 1×3+2=51 \times 3 + 2 = 5, row 5D0165\text{D}0_{16}. Sum 17416+5D016174_{16} + 5\text{D}0_{16}: 4+0=44 + 0 = 4; 7+D=20=16+47 + \text{D} = 20 = 16 + 4, write 4, carry 1; 1+5+1=71 + 5 + 1 = 7. Result 74416744_{16}; check 31×60=1860=7(256)+4(16)+431 \times 60 = 1860 = 7(256) + 4(16) + 4. 4.816×2.4164.8_{16} \times 2.4_{16}: compute 4816×241648_{16} \times 24_{16}, then put back two fractional digits. By 4: 8×4=32=2(16)+08 \times 4 = 32 = 2(16) + 0, write 0, carry 2; 4×4+2=18=16+24 \times 4 + 2 = 18 = 16 + 2, write 2, carry 1, row 12016120_{16}. By 2, shifted: 8×2=168 \times 2 = 16, write 0, carry 1; 4×2+1=94 \times 2 + 1 = 9, row 90016900_{16}. Sum A2016\text{A}20_{16}, so A.2016=A.216\text{A}.20_{16} = \text{A}.2_{16}. Check: 4.5×2.25=10.125=10+2164.5 \times 2.25 = 10.125 = 10 + \dfrac{2}{16}.

h)

1000=16(62)+81000 = 16(62) + 8, 62=16(3)+1462 = 16(3) + 14, 3=16(0)+33 = 16(0) + 3, so 1000=3E8161000 = 3\text{E}8_{16}; and 255=FF16255 = \text{FF}_{16}, written 0FF160\text{FF}_{16} to line up. Subtraction 3E816−0FF163\text{E}8_{16} - 0\text{FF}_{16}: ones 8<F8 < \text{F}, borrow, 8+16−15=98 + 16 - 15 = 9, and E becomes D; sixteens D<F\text{D} < \text{F}, borrow, 13+16−15=14=E13 + 16 - 15 = 14 = \text{E}, and 3 becomes 2; 2−0=22 - 0 = 2. Result 2E9162\text{E}9_{16}; back: 2(256)+14(16)+9=512+224+9=745=1000−2552(256) + 14(16) + 9 = 512 + 224 + 9 = 745 = 1000 - 255. Then 12.75=C.C1612.75 = \text{C}.\text{C}_{16}, since 12=C12 = \text{C} and 0.75=12160.75 = \dfrac{12}{16}, and 2.5=2.8162.5 = 2.8_{16} since 0.5=8160.5 = \dfrac{8}{16}. Compute CC16×2816\text{CC}_{16} \times 28_{16}. By 8: C×8=96=6(16)+0\text{C} \times 8 = 96 = 6(16) + 0, write 0, carry 6; C×8+6=102=6(16)+6\text{C} \times 8 + 6 = 102 = 6(16) + 6, write 6, carry 6, row 66016660_{16}. By 2, shifted: C×2=24=16+8\text{C} \times 2 = 24 = 16 + 8, write 8, carry 1; C×2+1=25=16+9\text{C} \times 2 + 1 = 25 = 16 + 9, write 9, carry 1, row 1980161980_{16}. Sum 66016+198016660_{16} + 1980_{16}: 0+0=00 + 0 = 0; 6+8=14=E6 + 8 = 14 = \text{E}; 6+9=15=F6 + 9 = 15 = \text{F}; 0+1=10 + 1 = 1. Result 1FE0161\text{FE}0_{16}, and with two fractional digits 1F.E016=1F.E161\text{F}.\text{E}0_{16} = 1\text{F}.\text{E}_{16}. Back: 16+15+1416=31.87516 + 15 + \dfrac{14}{16} = 31.875, and 12.75×2.5=31.87512.75 \times 2.5 = 31.875. The loop is closed: when the round trip comes out right, the conversion and the long calculation are validated in one go; when it does not, the error is in one of the two, and it is quickly located by rechecking the two conversions first.

Exercise 7: Overflow: when the result no longer fits

An overflow occurs when the exact result of an operation falls outside the representable range. The machine does not stop: it returns the truncated pattern, which is wrong. You therefore have to be able to DETECT the situation, and not confuse the carry out, which concerns unsigned arithmetic, with overflow, which concerns signed arithmetic.

  • a) With 8-bit signed integers, compute 100+50100 + 50. What does the machine return?
  • b) State the rule that detects a signed overflow from the signs of the operands and of the result.
  • c) With 8-bit unsigned integers, compute 200+100200 + 100. What does the machine return?
  • d) Does (−100)+(−50)(-100) + (-50) overflow with 8-bit signed integers?
  • e) Can 100+(−50)100 + (-50) overflow with 8-bit signed integers? Justify without computing.

Type your answers, the page tells you right or wrong 0/8

a)
b)
c)
d)
e)
Show the solution

Answers

  • a) The machine returns −106-106: overflow, since 150>127150 > 127
  • b) Signed overflow if and only if both operands have the same sign and the result the opposite sign
  • c) The machine keeps 4444 and raises the carry out: unsigned carry, not signed overflow
  • d) Yes: −150<−128-150 < -128, the pattern obtained is 106106
  • e) No: opposite signs, the sum lies between −50-50 and 100100
a)

100=01100100100 = 01100100 and 50=0011001050 = 00110010. The addition gives 1001011010010110. The most significant bit is 1: read as signed, the result is 150−256=−106150 - 256 = -106. Adding two positive numbers gives a negative one: that is an overflow. The exact value, 150150, exceeds the ceiling 127127, and the two's complement wheel shows why: moving 50 steps forward from 100, you cross the boundary between 127127 and −128-128.

b)

Rule: a signed overflow occurs exactly when both operands have the SAME sign and the result has the opposite sign. Two numbers of opposite signs can never overflow, since their sum lies between the two. The processor implements this rule with an XOR between the carry into and the carry out of the most significant bit, which gives the same verdict.

c)

200+100=300200 + 100 = 300, but the unsigned ceiling on 8 bits is 255255. The machine keeps 300−256=44300 - 256 = 44 and raises the carry out. The pattern kept is 0010110000101100. Here there is no signed overflow in the sense of rule b): there is an unsigned carry. The two flags, carry and overflow, are computed at the same time by the processor, and it is the program that chooses which one to look at, according to the declared type of the variables.

d)

−100-100 and −50-50 have the same sign, and their exact sum −150-150 is below the floor −128-128: there is an overflow. The pattern obtained corresponds to −150+256=106-150 + 256 = 106, a positive number. The rule is confirmed: two negatives giving a positive.

e)

No. The operands have opposite signs, so their sum lies between −50-50 and 100100, that is, strictly inside the range [−128,127][-128, 127]. This is a bounding argument, not a calculation: the sum of a positive and a negative number always lies between the two, so inside the range as soon as both operands are. A signed addition overflow can therefore always be detected by looking at the signs alone.

−128−1060100127+27+22+1: exit on the right, re-enter on the left

Part B: problems and reasoning (/50)

Exercise 8: Hexadecimal, masks and bitwise operations

Hexadecimal is not a base for computing: it is a compact way of writing binary. One hexadecimal digit is exactly 4 bits, one octal digit exactly 3 bits, which makes the conversions immediate by grouping, starting from the RIGHT. Bitwise operations, for their part, act on each position independently, with no carry at all.

  • a) Convert 101111101110111121011111011101111_2 to hexadecimal, then to octal.
  • b) AND\text{AND} denotes the bitwise conjunction. What is B616\text{B6}_{16} AND 0F16\text{0F}_{16}? And B616\text{B6}_{16} AND F016\text{F0}_{16}?
  • c) Which operation forces bit 2 to 1 without touching the others? Which operation inverts it?
  • d) What is 101121011_2 shifted 3 positions to the left, then 2 positions to the right?
  • e) How can you test whether an integer is even with a single bitwise operation?
  • f) Why is the binary to octal conversion done in groups of 3 and not 4?

Type your answers, the page tells you right or wrong 0/16

a)
b)
c)
d)
e)
f)
Show the solution

Answers

  • a) BEEF16=1373578=48 879\text{BEEF}_{16} = 137357_8 = 48\,879
  • b) 66 and B016=176\text{B}0_{16} = 176, whose sum gives back 182182
  • c) OR with 0000010000000100 to set, XOR with the same mask to toggle
  • d) 8888 then 2222
  • e) nn AND 11 equals 0
  • f) Because 8=238 = 2^{3}: one octal digit is 3 bits, one hexadecimal digit 4
a)

Groups of 4 from the right: 1011 1110 1110 11111011\ 1110\ 1110\ 1111, that is B,E,E,F\text{B}, \text{E}, \text{E}, \text{F}: the number is written BEEF16\text{BEEF}_{16}. Check with the weights: 11(4096)+14(256)+14(16)+15=45056+3584+224+15=48 87911(4096) + 14(256) + 14(16) + 15 = 45056 + 3584 + 224 + 15 = 48\,879. For octal, split the SAME binary again into groups of 3 from the right, padding on the left with a zero: 1 011 111 011 101 1111\ 011\ 111\ 011\ 101\ 111, that is 1373578137357_8. Check: 1(32768)+3(4096)+7(512)+3(64)+5(8)+7=48 8791(32768)+3(4096)+7(512)+3(64)+5(8)+7 = 48\,879. The grouping must start from the right; starting from the left is the most frequent error, and it shifts everything.

b)

B616=101101102=182\text{B6}_{16} = 10110110_2 = 182. The mask 0F=00001111\text{0F} = 00001111 keeps the 4 low-order bits and clears the others: the result is 00000110=600000110 = 6. The mask F0=11110000\text{F0} = 11110000 keeps the 4 high-order bits: the result is 10110000=B016=17610110000 = \text{B0}_{16} = 176. Check: 176+6=182176 + 6 = 182; the two halves rebuild the byte. An AND is always used to CLEAR bits.

c)

To force a bit to 1 without touching the others, OR it with a mask that has a 1 only in that position: here OR 00000100\text{OR}\ 00000100. To invert that single bit, XOR it with the same mask, since x⊕1=x‾x \oplus 1 = \overline{x} and x⊕0=xx \oplus 0 = x. Three roles to remember: AND to clear, OR to set, XOR to toggle.

d)

10112=111011_2 = 11. Shifted 3 positions to the left: 10110002=881011000_2 = 88, that is 11×2311 \times 2^{3}. That result shifted 2 positions to the right gives 101102=2210110_2 = 22, that is 88÷488 \div 4. Careful: the right shift is an INTEGER division; the bits pushed out are lost, and 1111 shifted right by 1 position gives 5, not 5.55.5.

e)

An integer is even if and only if its bit 0 is 0, so the test reads: nn AND 11 equals 0. One operation, against a division and a remainder for the test n mod 2=0n \bmod 2 = 0. It is the classic optimization, and it remains correct for negative integers in two's complement, since bit 0 keeps the same meaning there.

f)

Because a base-bb digit encodes exactly log⁡2b\log_{2}b bits: 16=2416 = 2^{4} gives 4 bits per hexadecimal digit, and 8=238 = 2^{3} gives 3 bits per octal digit. The grouping works only because the base is a power of 2; there is no similar grouping toward base 10, and that is why the binary to decimal conversion requires divisions or weights.

Exercise 9: Computer codes: ASCII, BCD, Gray and parity

A code is not a base: it is a convention that associates a bit pattern with a symbol or a digit. The same pattern 0100000101000001 means 65, or the letter A, or anything else, depending on the code applied. A bit pattern never carries its interpretation with it.

  • a) The letter A is 65 in ASCII. Write its pattern on 8 bits. The letter a is 97: what is the difference, and where does it show in the pattern?
  • b) Write 47 in BCD, then in pure binary. Compare the number of bits used.
  • c) The 3-bit Gray code is 000,001,011,010,110,111,101,100000, 001, 011, 010, 110, 111, 101, 100. What property does it satisfy? Give the conversion rule from binary.
  • d) The 7-bit word 10110111011011 is protected by an even parity bit. Which bit is added?
  • e) Does this code detect two simultaneous errors? Does it correct an error?

Type your answers, the page tells you right or wrong 0/15

a)
b)
c)
d)
e)
Show the solution

Answers

  • a) A is 0100000101000001, a is 0110000101100001: only bit 5 changes, hence the gap of 3232
  • b) 0100 01110100\ 0111 on 8 bits in BCD, 1011112101111_2 on 6 bits in pure binary
  • c) Only one bit changes between two consecutive codes; Gray bit kk is the XOR of binary bits kk and k+1k+1
  • d) The parity bit is 1, the transmitted word is 1011011110110111
  • e) It detects a single error, not two errors, and corrects nothing
a)

65=64+165 = 64 + 1, so A is written 0100000101000001. And 97=64+32+197 = 64+32+1, so a is written 0110000101100001. The difference is 32=2532 = 2^{5}: the only bit that changes is bit 5. Going from an uppercase letter to its lowercase therefore amounts to forcing that bit to 1, and the reverse to clearing it. That is why converting to lowercase was historically coded as a simple OR with 0010000000100000, with no table at all.

b)

In BCD, each decimal digit is encoded separately on 4 bits: the 4 becomes 01000100, the 7 becomes 01110111, so 4747 is written 0100 01110100\ 0111, that is, 8 bits. In pure binary, 47=32+8+4+2+1=101111247 = 32+8+4+2+1 = 101111_2, that is, 6 bits. BCD wastes space, since it uses only 10 of the 16 patterns of each nibble, but it makes display immediate, digit by digit. It is still found in displays, clocks and some financial formats, where exact conversion to decimal matters more than compactness.

c)

Two consecutive codes differ in only one bit, including between the last and the first. The conversion rule: bit kk of the Gray code is the XOR of bit kk and bit k+1k+1 of the binary numeral. For example 5=10125 = 101_2 gives a first bit 1⊕0=11 \oplus 0 = 1, a second 0⊕1=10 \oplus 1 = 1, a third 1⊕0=11 \oplus 0 = 1, that is 111111, which is indeed the sixth word of the list. The benefit is physical: on a position sensor, if two bits changed at the same time, a slight timing offset between them would produce an absurd intermediate value. With Gray code, only one bit is ever in transition.

d)

The word 10110111011011 contains five 1s, an odd number. For the total to be even, the parity bit is 1, and the transmitted word becomes 1011011110110111, which contains six 1s. Check on reception: count the 1s again; if there is an odd number of them, an error has occurred.

e)

It detects any error affecting an ODD number of bits, so a single error, but not two simultaneous errors: two flipped bits leave the parity unchanged and the error goes unnoticed. And it corrects nothing, since it only signals that an error exists, without saying where. Correcting requires more redundancy, for example a Hamming code, which adds several check bits placed so as to point to the position of the faulty bit.

Exercise 10: Five statements to correct

Each of the following five statements is FALSE. Say why and give the correct statement.

  • 1) “In binary, appending a 0 on the right multiplies the number by 10.”
  • 2) “On 8 bits, two's complement represents the integers from −127-127 to +127+127.”
  • 3) “The pattern 1111111111111111 is −1-1.”
  • 4) “A byte is written with four hexadecimal digits.”
  • 5) “With enough bits, 0.10.1 can eventually be written exactly in binary.”

Type your answers, the page tells you right or wrong 0/11

1)
2)
3)
4)
5)
Show the solution

Answers

  • 1) FALSE: the base is 2, so the factor is 2. 1012=5101_2 = 5 becomes 10102=101010_2 = 10
  • 2) FALSE: the range is [−128,127][-128, 127], that is [−2n−1,2n−1−1][-2^{n-1}, 2^{n-1}-1]
  • 3) FALSE: −1-1 as signed, 255255 as unsigned. The type is set by the program, not by the memory
  • 4) FALSE: a byte is written with TWO hexadecimal digits, from 0000 to FF\text{FF}
  • 5) FALSE: 0.10.1 has no terminating binary expansion; the factor 5 in the denominator rules it out
1)

FALSE. Appending a zero on the right multiplies by the BASE, and the base is 2. Counterexample: 1012=5101_2 = 5 becomes 10102=101010_2 = 10, twice as much, not ten times as much. Correct statement: in base bb, appending a zero on the right multiplies by bb; in binary, by 2, and kk zeros multiply by 2k2^{k}.

2)

FALSE. The range is −128-128 to +127+127: it is asymmetric, because zero uses up a pattern on the positive side. Counting the patterns is enough to see it: 128128 patterns for the negative numbers, 128128 for zero and the positive numbers. Correct statement: on nn bits, two's complement covers [−2n−1, 2n−1−1][-2^{n-1},\ 2^{n-1}-1].

3)

FALSE. The pattern does not carry its interpretation: 1111111111111111 is −1-1 if it is read as a signed integer on 8 bits, but 255255 if it is read as an unsigned integer. It means something else again if it is read as a character or as part of a floating-point number. Correct statement: the value of a pattern depends on the declared type, and it is the program, not the memory, that sets that type.

4)

FALSE. One hexadecimal digit is 4 bits, so an 8-bit byte is written with exactly TWO hexadecimal digits, from 0000 to FF\text{FF}. Four hexadecimal digits describe 16 bits, that is, two bytes. Correct statement: nn bits require n/4n/4 hexadecimal digits, rounded up.

5)

FALSE. 0.1=1100.1 = \dfrac{1}{10} and 10=2×510 = 2 \times 5 contains the factor 5. A number has a terminating binary expansion only if its reduced denominator is a power of 2: the expansion of 0.10.1 is repeating, and adding bits only pushes the rounding further back. Correct statement: 0.10.1 has no terminating binary expansion, whatever the number of bits; that is why 0.1+0.20.1+0.2 is not exactly 0.30.3 on a computer.

Exercise 11: Problem: colours, memory and the size of an image

A screen colour is written in hexadecimal in the form #RRGGBB: two hexadecimal digits per component, red, green and blue, each component taking up one byte. A raster image stores one such colour per pixel.

  • a) Break down the colour #3C78D8\#3\text{C}78\text{D}8 into its three decimal components.
  • b) How many distinct colours does this encoding allow?
  • c) An address bus has 16 lines. How many bytes can be addressed?
  • d) How much space does an image of 800 by 600 pixels in 24-bit colour take, in bytes and then in mebibytes?
  • e) Is the same 16-line bus enough to address this image? How many lines would be needed?
  • f) Is the colour #FFFFFF\#\text{FFFFFF} white or black? And #000000\#000000?

Type your answers, the page tells you right or wrong 0/15

a)
b)
c)
d)
e)
f)
Show the solution

Answers

  • a) (60,120,216)(60, 120, 216)
  • b) 2563=224=16 777 216256^{3} = 2^{24} = 16\,777\,216 colours
  • c) 216=65 5362^{16} = 65\,536 bytes, that is 64 KiB
  • d) 480 000480\,000 pixels, 1 440 0001\,440\,000 bytes, about 1.371.37 MiB
  • e) No: 21 lines are needed, since 220<1 440 000≤2212^{20} < 1\,440\,000 \le 2^{21}
  • f) #FFFFFF\#\text{FFFFFF} is white, #000000\#000000 black: the synthesis of a screen is additive
a)

Split into three pairs: 3C3\text{C}, 7878, D8\text{D}8. Red: 3(16)+12=603(16)+12 = 60. Green: 7(16)+8=1207(16)+8 = 120. Blue: 13(16)+8=21613(16)+8 = 216. The colour is therefore (60,120,216)(60, 120, 216), a strong blue, as the dominant blue component confirms.

b)

Each component takes 256256 values, and the three are independent: 2563=224=16 777 216256^{3} = 2^{24} = 16\,777\,216 colours. That is the famous 16 million colours, and the calculation is done by adding the bits, 8+8+8=248+8+8 = 24, rather than multiplying 256 three times.

c)

With 16 address lines, you form 216=65 5362^{16} = 65\,536 distinct addresses, that is, 64 kibibytes if each address designates one byte. Each extra line doubles the addressable capacity: it is a doubling, not an addition, and that is why moving from 32-bit to 64-bit addressing did not double the limit but put it out of reach.

d)

The image has 800×600=480 000800 \times 600 = 480\,000 pixels, at 3 bytes each: 1 440 0001\,440\,000 bytes. Since a mebibyte is 220=1 048 5762^{20} = 1\,048\,576 bytes, that makes 1 440 000/1 048 576≈1.371\,440\,000 / 1\,048\,576 \approx 1.37 MiB. Order-of-magnitude check: half a million pixels at 3 bytes is about one and a half million bytes, so a little more than one mebibyte.

e)

No: 65 53665\,536 addresses are not enough for 1 440 0001\,440\,000 bytes. You need nn such that 2n≥1 440 0002^{n} \ge 1\,440\,000. Since 220=1 048 5762^{20} = 1\,048\,576 is too small and 221=2 097 1522^{21} = 2\,097\,152 is enough, 21 address lines are needed. The reasoning brackets the value between two powers of 2, never by division.

f)

#FFFFFF\#\text{FFFFFF} sets all three components to their maximum, 255255: it is white, the sum of the three lights. #000000\#000000 sets them to zero: no light emitted, it is black. The synthesis is additive because a screen emits light; on paper, ink absorbs and the logic is reversed, which explains why white there is the absence of ink.

Exercise 12: Problem: the IEEE 754 standard in single precision

A single-precision floating-point number takes up 32 bits: 1 sign bit, 8 exponent bits with a bias of 127127, and 23 mantissa bits. The number is written (−1)s×1.m×2e−127(-1)^{s} \times 1.m \times 2^{e-127}: the leading 1 is not stored, since it is always there after normalization.

  • a) Write 6.256.25 in binary.
  • b) Normalize this numeral in the form 1.m×2k1.m \times 2^{k}.
  • c) Compute the biased exponent, then give the 32 bits of −6.25-6.25.
  • d) Write these 32 bits in hexadecimal.
  • e) Up to which integer are all the integers represented exactly in single precision?
  • f) Are two neighbouring floating-point numbers separated by a constant gap?

Type your answers, the page tells you right or wrong 0/14

a)
b)
c)
d)
e)
f)
Show the solution

Answers

  • a) 6.25=110.0126.25 = 110.01_2
  • b) 1.10012×221.1001_2 \times 2^{2}
  • c) Stored exponent 129129, sign 1: 1 10000001 100100000000000000000001\ 10000001\ 10010000000000000000000
  • d) C0C8000016\text{C0C80000}_{16}
  • e) 224=16 777 2162^{24} = 16\,777\,216
  • f) No: the gap is 2−23×2k2^{-23}\times 2^{k}, it grows with the order of magnitude
a)

Integer part: 6=11026 = 110_2. Fractional part: 0.25=2−20.25 = 2^{-2}, so 0101 after the binary point. Hence 6.25=110.0126.25 = 110.01_2. Check: 4+2+0.25=6.254 + 2 + 0.25 = 6.25.

b)

Move the binary point two positions to the left, which is compensated by a factor 222^{2}: 110.012=1.10012×22110.01_2 = 1.1001_2 \times 2^{2}. Check: 1.10012=1+0.5+0.0625=1.56251.1001_2 = 1 + 0.5 + 0.0625 = 1.5625, and 1.5625×4=6.251.5625 \times 4 = 6.25. Normalization requires exactly one 1 before the point, which makes the representation unique and makes it possible not to store that 1.

c)

The actual exponent is 22, so the stored exponent is 2+127=129=1000000122 + 127 = 129 = 10000001_2. The sign is negative, so s=1s = 1. The mantissa is the part after the point, 10011001, padded with zeros to 23 bits. The 32 bits are: 1 10000001 100100000000000000000001\ 10000001\ 10010000000000000000000. Numerical check: read as an unsigned integer, this pattern is 231+129×223+222+219=3 234 332 6722^{31} + 129 \times 2^{23} + 2^{22} + 2^{19} = 3\,234\,332\,672.

d)

Group the 32 bits in fours from the left, which is legitimate since 32 is a multiple of 4: 1100 0000 1100 1000 0000 0000 0000 00001100\ 0000\ 1100\ 1000\ 0000\ 0000\ 0000\ 0000, that is C0C8000016\text{C0C80000}_{16}. Check: C0C80000\text{C0C80000} is indeed 3 234 332 6723\,234\,332\,672, the same value as in the previous question.

e)

The mantissa has 23 stored bits plus the implicit 1, that is, 24 significant bits. All the integers up to 224=16 777 2162^{24} = 16\,777\,216 are therefore written exactly. Beyond that, only every other integer can be represented, then one in four, and so on. That is why a seconds counter or an identifier stored in single precision goes wrong from about 17 million on, without the slightest error message.

f)

No. The gap between two consecutive floats is 2−23×2k2^{-23} \times 2^{k}: it depends on the exponent, and so on the order of magnitude of the number. Near 1, the gap is about 10−710^{-7}; near 10610^{6}, it is about 0.060.06. Floats are tightly packed near zero and more and more spread out as you move away from it, exactly like the marks on a logarithmic scale. Practical consequence: adding a small number to a large one may change nothing at all, which makes a sum depend on the order of its terms.

1100000011001 0000 0000 0000 0000 000exponent, 8 bitsmantissa, 23 bitssign: 1 = negativeexponent: 129hex: C0C80000
Something missing from this set? A type of exercise your teacher gives, a problem you are stuck on, a mistake you spotted: tell me, I read every request.

Sending goes through your free space: that is how I can answer you and tell you when the exercise is added. An email is enough, no password. Create your space. Rather not create an account? Write to me directly.

What is it about?
I read every request myself, nobody else sees it. No need to write your name or your school.
When your request is dealt with, you hear about it by email and in your space.

By sending, you agree that I read your request to answer it. It is kept with your account, erased with it, and never published: privacy policy.

Previous chapter Proof techniques, 201-N11 Next chapter Modular arithmetic, 201-N11

© Ahmed Squalli Houssaini. Exercise set published at www.letuteurscientifique.ca/en/exercices/cegep-n11-number-systems. Free for personal and classroom use; republishing it elsewhere requires written permission (legal notice).

See also

Looking for a computer science math tutor in Montreal?

Get in touch for a first session. With a B.Sc. in computer science from McGill and an M.Sc. in applied computer science from Concordia, I work through number systems on what actually breaks in real programs: silent overflows and floating-point comparisons.

Site by Studio Squalli