| English | 意味 |
|---|---|
| overflow/ˌəʊvəˈfləʊ/ | オーバーフロー |
| two's complement/tuːz ˈkɒmplɪmənt/ | 補数 |
| register/ˈredʒɪstə/ | レジスタ |
| sign bit/saɪn bɪt/ | 符号ビット |
| most significant bit/məʊst sɪɡˈnɪfɪkənt bɪt/ | 最上位ビット |
| one's complement/wʌnz ˈkɒmplɪmənt/ | 反転数 |
| Binary Coded Decimal/ˈbaɪnəri ˈkəʊdɪd ˈdesɪml/ | BCD(二進コード付き十進数) |
The bank that lost a day
- On 1 September 1983 the Vancouver Stock Exchange index stood at 524.811. It had opened at 1000 twenty-two months earlier, and the market had risen the whole time.
- The program recalculated the index after every trade, truncating rather than rounding each time. Each truncation lost a fraction of a point. Three thousand trades a day did the rest.
- When it was recomputed properly the index was 1098.892: the arithmetic, not the market, had halved it.
- Arithmetic on a fixed number of bits is not the arithmetic you learned at school. This lesson is binary addition, overflow 溢出, subtraction by two's complement 补码, signed integers, and BCD.
Binary addition
- Add column by column from the right, carrying into the next column, exactly as in denary.
- The rules: $0 + 0 = 0$; $0 + 1 = 1$; $1 + 1 = 10$, write 0 and carry 1; $1 + 1 + 1 = 11$, write 1 and carry 1.
0101$+$0011$=$1000, that is $5 + 3 = 8$.

Same method as denary, only two digits to carry between
二進数 & 符号付き整数
byte = Σ 桁の値
8ビットのパターンがどのように数値にマッピングされ、255を超えてオーバーフローするかを確認してください。
二進数 0101 + 0011 を加算してください。4ビットの結果を答えよ。
難易度 1/5 · 100 コイン + 今日初回完了時に小ボーナス付与
$5 + 3 = 8$ は、二進数で 1000 です。
Overflow
- Overflow happens when the result of a calculation needs more bits than the register 寄存器 can hold. The carry out of the most significant column is lost, so the stored answer is wrong.
- It is a property of the register width, not of the number 255: in a 16-bit register the same sum is fine.
- In signed arithmetic the tell-tale is a sign bit that flips wrongly: two positives giving a negative, or two negatives giving a positive.
二進加算におけるオーバーフローとは:
難易度 1/5 · 100 コイン + 今日初回完了時に小ボーナス付与
和が利用可能なビットに収まりきらない場合にオーバーフローが発生し、左端の列からの Carry out が失われます。
Worked example: name the overflow properly
- Add the 8-bit unsigned integers
10110101and01101100and comment on the result. - The sum is
1 0010 0001, which needs 9 bits. The true result is 289. - Full answer: overflow has occurred, because 289 is larger than the largest value an 8-bit register can hold, 255; the carry out of the most significant bit is lost, so the stored result
0010 0001is 33, which is wrong. - The mark is for naming the register width and saying the result cannot be represented in it. "The answer was more than 255" alone does not score.
2つの8ビット符号なし整数を加算した結果が9ビット必要な場合、満点となる説明はどれですか?
難易度 1/5 · 100 コイン + 今日初回完了時に小ボーナス付与
レジスタ幅を名指し、結果をそこに表現できないことを述べ、Carryについてどうなるかを述べる。他の選択肢は原因なしに症状を述べているだけである。
Subtraction by two's complement
- To calculate $A - B$: form the two's complement of $B$ by inverting every bit and adding 1, add it to $A$, then discard any final carry-out.
- $100 - 30$ in 8 bits: two's complement of
0001 1110is1110 0001inverted, plus 1, so1110 0010. 0110 0100$+$1110 0010$=$1 0100 0110; discard the leading 1 and read0100 0110$= 70$. ✓

Subtraction becomes addition, which is why processors need no subtractor
0011 の4ビット2の補数を求めよ。(反転してから1を加える)
難易度 1/5 · 100 コイン + 今日初回完了時に小ボーナス付与
0011 を反転 → 1100、次に1を加える → 1101(これは $-3$ を表す)。
2の補数を用いてAからBを引く手順を正しい順序で並べ替えてください。
難易度 3/5 · 200 コイン + 今日初回完了時に小ボーナス付与
反転、1足し、加算、破棄。この破棄が答えをレジスタの幅内に留める要因である。
Two's complement signed integers
- In an $n$-bit two's complement number the most significant bit 最高有效位 is the sign bit 符号位: 0 means positive, 1 means negative. Equivalently, the top bit carries a negative place value, $-2^{n-1}$.
- To read a negative number: invert every bit, add 1, then put a minus sign in front.
1011 0100inverts to0100 1011, plus 1 is0100 1100$= 76$, so the value is $-76$. Check by place value: $-128 + 32 + 16 + 4 = -76$. ✓ - For $n$ bits the range is $-2^{n-1}$ to $+2^{n-1} - 1$: 8 bits give $-128$ to $+127$, 12 bits give $-2048$ to $+2047$. The most negative value is a 1 followed by zeros; the most positive is a 0 followed by ones.

11111111 is 255 read one way and −1 read the other
2の補数による符号付きビット
左端のビットは負の位値を持ちます。どのビットでも反転させるか、Negate(すべてのビットを反転させてから1を加える)をクリックすると、符号付き値の変化を見ることができます。
8ビット2の補数 11111101 を符号付き十進数として読み取れ。
難易度 2/5 · 140 コイン + 今日初回完了時に小ボーナス付与
MSBは1(負)。反転 → 00000010、1を加える → 00000011 $= 3$、したがって値は $-3$ である。
8ビット2の補数で表現できる最大の正の値は何ですか?
難易度 2/5 · 140 コイン + 今日初回完了時に小ボーナス付与
範囲は $-2^{7}$ から $2^{7}-1$ 、つまり $-128$ から $+127$ 。最大値は 01111111 = 127。
Worked example: write −108 in 12 bits
- Start from $+108$ in 12 bits: $108 = 64 + 32 + 8 + 4$, so
0000 0110 1100. - Invert every bit:
1111 1001 0011. Add 1:1111 1001 0100. - Check with place values, where the top bit is worth $-2048$: $-2048 + 1024 + 512 + 256 + 128 + 16 + 4 = -108$. ✓
- The commonest error is sign and magnitude: setting the top bit to 1 and leaving the rest. That is a different, older scheme and scores zero here.
−108 を12ビット2の補数として書きなさい(スペースは可)。
難易度 1/5 · 100 コイン + 今日初回完了時に小ボーナス付与
+108 は 0000 0110 1100;これを反転して 1111 1001 0011 にし、1を加える。確認:−2048 + 1024 + 512 + 256 + 128 + 16 + 4 = −108。
One's complement
- One's complement 反码 is the older scheme: a negative is made by inverting every bit of the positive, with no add-1 step. $+30$ is
0001 1110, so $-30$ is1110 0001. - Its drawback is two zeros,
0000 0000and1111 1111, which wastes a bit pattern and complicates the arithmetic. - Two's complement has one zero and lets the same adder circuit do subtraction, which is why it won.
1の補数が2の補数より好まれるのは、0の表現が1つだけだからである。
難易度 1/5 · 100 コイン + 今日初回完了時に小ボーナス付与
逆の場合:1の補数はゼロが2つあり、+0 と −0 となる。2の補数は1つだけあり、加算器に引き算をさせることができる。
Binary Coded Decimal
- In Binary Coded Decimal 二进制编码十进制 (BCD) each denary digit is stored as its own 4-bit pattern, using only
0000to1001. - 93 in BCD is
1001 0011, which is not the same as 93 in pure binary,0101 1101. Reading one as the other is a favourite exam trap. - Uses: calculators, digital clocks and seven-segment displays, where each digit is driven separately, and currency, where BCD avoids the rounding errors of storing $0.1$ in pure binary. The cost is wasted patterns, since
1010to1111are never used.

One digit, one nibble, one display
十進数字 $9$ を4ビットBCDパターンとして書きなさい。
難易度 1/5 · 100 コイン + 今日初回完了時に小ボーナス付与
$9$ は 1001 です。BCDでは、各十進数字が独自のニブル(0000–1001)を持つ。
各ビットパターンが何を表しているかに一致させよ。
難易度 2/5 · 140 コイン + 今日初回完了時に小ボーナス付与
ビット自体に読み取り方法を指定する情報は含まれていません。合意された表現方法が値を決定します。
Marks that slip away
- Explain overflow with the register width the question gave, not with "it was more than 255".
- To negate, invert and add 1. Setting the top bit to 1 is sign and magnitude, a different scheme.
- Two's complement subtraction ends by discarding the final carry-out. Keeping it gives a nine-bit answer.
- BCD stores each digit separately; pure binary stores the whole number.
1001 0011is 93 in BCD and 147 in binary.
You've got it
- add column by column with carries; overflow is a result needing more bits than the register holds, and the answer names that width
- subtract by adding the two's complement, invert and add 1, then discard the final carry
- signed: the MSB is the sign bit and carries $-2^{n-1}$; range $-2^{n-1}$ to $+2^{n-1}-1$; read a negative by inverting, adding 1 and negating
- one's complement inverts only and has two zeros; BCD stores each denary digit in its own nibble, for clocks, calculators and currency