Binary arithmetic and signed integers
導入済み
21:52
数系とデータ
この写真。この曲。この動画そのもの。あなたの名前、メッセージ、すべてのデバイスのすべてのファイル——コンピュータ内部では、すべてがゼロと一でしかありません。…
英語のナレーション・英語と中国語の字幕を切り替え可能
このレッスンの内容
| English | 意味 |
|---|---|
| truncating | Removing digits after a chosen position without changing the remaining digits. |
| rounding/ˈraʊndɪŋ/ | Changing a number to the nearest value with a chosen number of digits. |
| bits/bɪts/ | A binary digit, taking the value zero or one. |
| binary addition | The process of adding numbers written using the digits zero and one. |
| overflow/ˌəʊvəˈfləʊ/ | オーバーフロー |
| two's complement/tuːz ˈkɒmplɪmənt/ | 補数 |
| signed integers | Whole numbers represented in a form that allows both positive and negative values. |
| carrying | Moving a value into the next column when adding digits. |
| denary/ˈdiːnəri/ | The base-ten number system, using the digits zero through nine. |
| register/ˈredʒɪstə/ | レジスタ |
| unsigned addition | The process of adding whole numbers represented without a sign. |
| carry out | A bit carried beyond the leftmost position available for the result. |
| most significant bit/məʊst sɪɡˈnɪfɪkənt bɪt/ | 最上位ビット |
| register width/ˈredʒɪstə wɪtθ/ | The number of bits a register can hold at one time. |
| signed arithmetic | Calculations using numbers represented in a form that allows positive and negative values. |
| sign bit/saɪn bɪt/ | 符号ビット |
| unsigned integers | Whole numbers represented without a sign, allowing only zero and positive values. |
| inverting/ɪnˈvɜːtɪŋ/ | Changing every zero bit to one and every one bit to zero. |
| processors/ˈprəʊsesəz/ | The component that executes instructions and performs the operations of a computer or similar system. |
| subtractor | A circuit that subtracts one binary number from another. |
| place value/pleɪs ˈvæljuː/ | The value of a digit's position within a number. |
| sign and magnitude | A way to represent signed numbers using one bit for the sign and the rest for size. |
| One's complement/wʌnz ˈkɒmplɪmənt/ | The older scheme: a negative is made by inverting every bit of the positive, with no add-1 step. |
| bit pattern | A particular sequence of zeros and ones used to represent data. |
| adder circuit | A circuit that adds binary numbers to produce a result. |
| Binary Coded Decimal/ˈbaɪnəri ˈkəʊdɪd ˈdesɪml/ | BCD(二進コード付き十進数) |
| denary digit | One of the ten symbols used to write numbers in base ten. |
| pure binary | A way to represent a whole number directly using binary place values. |
| seven-segment displays | Devices that show digits using seven separately controlled sections of light. |
| nibble/ˈnɪbl/ | A group of four bits. |
一日を失った銀行
- 1983年9月1日、バンクーバー証券取引所指数は524.811であった。22ヶ月前に1000で始まったばかりであり、市場は常に上昇していた。
- 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.
- 適切に再計算されたとき、指数は1098.892だった:市場ではなく演算が半分にしたのである。
- 固定ビット数の算術演算は、学校で習う数学とは異なります。この授業では、二進加算、オーバーフロー、2の補数による減算、符号付き整数、BCDについて学びます。

二進加算
- 十進法と同じように、右から列ごとに足し算を行い、 carry( Carry bit)を次の列へ持ち上げます。
- 規則:$0 + 0 = 0$;$0 + 1 = 1$;$1 + 1 = 10$は0を書き carry 1を移す;$1 + 1 + 1 = 11$は1を書き carry 1を移す。
0101$+$0011$=$1000、つまり$5 + 3 = 8$。

十進法と同じ手法ですが、持ち上げる数字は2つだけです
Binary & signed integers
byte = Σ place values
See how an 8-bit pattern maps to a number (and how it would overflow past 255).
Add the binary numbers 0101 + 0011. Give the 4-bit result.
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
$5 + 3 = 8$, which is 1000 in binary.
オーバーフロー
- オーバーフローは、計算の結果がレジスタが保持できるビット数より多いときに起こる。最上位列からの carry out は失われるため、格納された答えは誤りとなる。
- 255という数字自体の性質ではなく、レジスタ幅の性質である:16ビットレジスタでは同じ和でも問題ない。
- 符号付き演算における兆候は、正しく反転しない符号ビットである:2つの正の数が負になる、または2つの負の数が正になる。
Overflow in binary addition means:
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
Overflow occurs when the result cannot be represented in the available bits. In unsigned addition a carry out indicates overflow; in two’s complement addition, two operands of the same sign producing a result of the opposite sign indicate overflow.
例題:オーバーフローを正しく名付ける
- 8ビット符号なし整数
10110101と01101100を加え、結果についてコメントせよ。 - 和は
1 0010 0001で、9ビット必要とする。真の結果は289である。 - 完全な回答:オーバーフローが発生している。なぜなら289は8ビットレジスタが保持できる最大値255より大きいからであり、最上位ビットからの carry out が失われるため、格納された結果
0010 0001は33となり、誤りである。 - 得点はレジスタ幅を名付け、結果がそれには表現できないことを述べる点である。「答えが255より大きかった」だけでは採点されない。

Two 8-bit unsigned integers are added and the result needs 9 bits. Which is the full-mark explanation?
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
Name the register width, say the result cannot be represented in it, and say what happens to the carry. The other options state a symptom without the cause.
2の補数による減算
- $A - B$を計算するには:$B$の2の補数を作るためにすべてのビットを反転して1を加え、$A$に加算し、最終的な carry out を破棄する。
- 8ビットでの$100 - 30$:
0001 1110の2の補数は1110 0001を反転して1を加えた1110 0010。 0110 0100$+$1110 0010$=$1 0100 0110;先頭の1を破棄して0100 0110$= 70$を読む。✓

減算は加算になるため、プロセッサには減算器が必要ない

What is the 4-bit two's complement of 0011? (invert, then add 1)
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
Invert 0011 → 1100, then add 1 → 1101 (which represents $-3$).
Put the steps of subtracting B from A by two's complement in order.
難易度 3/5 · 200 コイン + 今日初回達成時の小ボーナス
Invert, add one, add, discard. The discard is what keeps the answer in the register's width.
2の補数符号付き整数
- $n$ビットの2の補数数において最上位ビットは符号ビットである:0は正、1は負を意味する。あるいは、上位ビットが負の位値$-2^{n-1}$を持つと見なすこともできる。
- 負の数を読むには:すべてのビットを反転して1を加え、前にマイナス記号をつける。
1011 0100を反転すると0100 1011になり、1を加えると0100 1100$= 76$なので、値は$-76$である。位値で確認:$-128 + 32 + 16 + 4 = -76$。✓ - $n$ ビットでは範囲は $-2^{n-1}$ から $+2^{n-1} - 1$ : 8 ビットでは $-128$ から $+127$ 、 12 ビットでは $-2048$ から $+2047$ 。最も負の値は 1 に続くゼロ;最も正の値は 0 に続くワンである。

11111111は片方では255、もう片方では−1

Two's complement signed bits
The leftmost bit carries a 負 place value. Flip any bit — or hit Negate (invert every bit, then add 1) — and watch the signed value change.
Read the 8-bit two's complement number 11111101 as a signed denary value.
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
MSB is 1 (negative). Invert → 00000010, add 1 → 00000011 $= 3$, so the value is $-3$.
What is the largest positive value an 8-bit two's complement number can hold?
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
Range is $-2^{7}$ から $2^{7}-1$, i.e. $-128$ から $+127$. The maximum is 01111111 = 127.
例題:12ビットで−108を書く
- 12ビットでの$+108$から始める:$108 = 64 + 32 + 8 + 4$なので、
0000 0110 1100。 - すべてのビットを反転:
1111 1001 0011。1を加える:1111 1001 0100。 - 位値で確認、最上位ビットが$-2048$の価値を持つ:$-2048 + 1024 + 512 + 256 + 128 + 16 + 4 = -108$。✓
- 一般的な誤りは符号と絶対値である:最上位ビットを1にして残りをそのままにする。それは異なる古い方式であり、ここでは0点となる。
Write −108 as a 12-bit two's complement number (spaces allowed).
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
+108 is 0000 0110 1100; invert to 1111 1001 0011 and add 1. Check: −2048 + 1024 + 512 + 256 + 128 + 16 + 4 = −108.
1の補数
- 1の補数は古い方式である:負は正のすべてのビットを反転することで作られ、+1のステップはない。$+30$は
0001 1110なので、$-30$は1110 0001。 - その欠点は二重のゼロ
0000 0000と1111 1111があり、ビットパターンを浪費し、演算を複雑にする。 - 2の補数はゼロが一つあり、同じ加算回路で減算ができるので、これが勝利した理由である。
One's complement is preferred to two's complement because it has only one representation of zero.
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
The opposite: one's complement has two zeros, +0 and −0. Two's complement has one, and lets the adder do subtraction.
二進コード化十進法(BCD)
- **二進コード化十進法(BCD)**では、各十進数字を独立した 4 ビットのパターンとして保存し、
0000から1001の組み合わせのみを使用します。 - BCDにおける 93 は
1001 0011ですが、純粋な二進法の 93 や0101 1101とは異なります。これらを混同して読み取ることは、試験でよく出される罠です。 - 用途:電卓、デジタル時計、セグメント表示器(各数字を個別に駆動する)。通貨計算では、纯粋な二進法で $0.1$ を格納する際の丸め誤差を防ぐために使用されます。ただし、
1010から1111のパターンが使用されないため、効率面でのコストが発生します。

1桁、1ニブル、1ディスプレイ

Write the denary digit $9$ as a 4-bit BCD pattern.
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
$9$ is 1001. In BCD each denary digit gets its own nibble (0000–1001).
Match each bit pattern to what it represents.
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
Nothing in the bits says how to read them. The agreed representation decides the value.
見落としやすいポイント
- レジスター幅を用いてアンダーフローを説明すること。"255より大きかったから"という理由で説明してはならない。
- 逆数値(補数)を求めるには、反転させて1を加える。最上位ビットを1に設定することは符号付き magnitude 方式であり、異なる方式である。
- 2の補数による引き算では、最終的な桁上げ(carry-out)を無視する。これを残すと9ビットの答えになってしまう。
- BCD stores each digit separately; pure binary stores the whole number.
1001 0011is 93 in BCD and 147 in binary.
理解できましたか
- 桁ごとに桁上げを含めて加算する。アンダーフローとは、結果がレジスターが保持できるビット幅よりも多いことを指し、答えはその幅を特定するものとする。
- 引き算は2の補数を加えることで行う。すなわち、反転させて1を加え、最終的な桁上げを無視する。
- 符号付き:MSBは符号ビットであり、$-2^{n-1}$を持つ;範囲は$-2^{n-1}$から$+2^{n-1}-1$;負の値は反転して1を加え、符号を逆転させることで読み取る
- 1の補数は単に反転させるだけで、ゼロが2つ存在する。BCDは各十進数字を独立したニブルに格納するため、時計、電卓、通貨表示などに用いられる。
何が問題でしたか?この内容はサイトの運営チームだけが確認します。