数値表現とコード
導入済み
8:05
ディジタルロジック設計
Digital logic needs only two voltage levels, a handful of gates, and time. A three-input function has just eight rows, so checking every row is free, on paper…
英語のナレーション・英語と中国語の字幕を切り替え可能
このレッスンの内容
| English | 意味 |
|---|---|
| binary/ˈbaɪnəri/ | 2進法 |
| hexadecimal/ˌheksəˈdesɪml/ | 16進数 |
| two's complement/tuːz ˈkɒmplɪmənt/ | 2の補数 |
| range/reɪndʒ/ | 範囲 |
| overflow/ˌəʊvəˈfləʊ/ | オーバーフロー |
22.5 °C, held in bits
- A thermostat shows 22.5 °C, but the microcontroller behind it holds only bits: two voltage levels, 0 and 1.
- How does 22.5 become a pattern a machine can add, compare and store? And how do negative numbers fit? This lesson is that translation.
Binary: read the weights
- In binary 二进制 each position has a weight: 128, 64, 32, 16, 8, 4, 2, 1 for 8 bits. A pattern's value is the sum of the weights under its 1s.
- To convert an integer, divide by 2 and collect the remainders, or take the largest weights that fit: $156 = 128 + 16 + 8 + 4 = 10011100_{2}$.

What is the binary number 10110 in decimal?
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
$16 + 4 + 2 = 22$: 1 の下の重みを加える。
Hexadecimal and fractions
- Hexadecimal 十六进制 is binary's shorthand: each hex digit is exactly 4 bits. Group from the right: $1001\ 1100 = \text{9C}_{16}$.
- Fractions convert by doubling and keeping the integer part: $0.625 \to 1.25\ (1) \to 0.5\ (0) \to 1.0\ (1)$, so $0.625 = 0.101_{2}$, which is $0.5 + 0.125$. The thermostat's $22.5$ is $10110.1_{2}$.
What is the hexadecimal number 3F in decimal?
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
$3 \times 16 + 15 = 63$. In binary it is $0011\ 1111$.
Two's complement: invert and add one
- Two's complement 二进制补码 negates a number by inverting every bit and adding 1. In 8 bits, $5 = 00000101$, so $-5 = 11111010 + 1 = 11111011$.
- Why it works: modulo $2^{N}$, the negative of $b$ is $2^{N} - b = (2^{N} - 1 - b) + 1$, and $2^{N} - 1 - b$ is $b$ with every bit flipped. So the ordinary adder also subtracts.
The range, and reading a pattern
- N bits hold the range 范围 $-2^{N-1}$ to $2^{N-1} - 1$: −128 to +127 in 8 bits. The range is lopsided: −128 exists, +128 does not.
- A leading 1 means negative. To decode, read the bits as unsigned and subtract $2^{N}$: $10011100$ is 156 unsigned, and $156 - 256 = -100$.
Read a pattern both ways
10011100 is 156 unsigned and 156 − 256 = −100 in 8-bit two's complement. Change the value and watch the top bit's weight of −128 decide the sign.
8ビットの2の補数において、ビット 10011100 が表す値は何か?
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
先頭の 1 は負を意味する:$156 - 256 = -100$. 符号なしとして読むと、同じビット列は 156 であり、解釈によって異なる。
8ビットの2の補数で表現できる最も負の値は何か?
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
$-2^{7} = -128$, パターン $10000000$. 最大正の値は +127 であるため、範囲は1つずれている。
Overflow: the sign rule
- Overflow 溢出 happens when the true result is outside the range. Detect it by sign: two positives giving a negative, or two negatives giving a positive.
- A carry out of the top bit is not, by itself, overflow. In circuit terms, overflow is when the carry into the top bit differs from the carry out.
$100 + 50 = 150 > 127$. The 8-bit adder produces $10010110$, which decodes to $-106$. Positive plus positive reading negative: overflow. The machine did not fail; the width did.
8ビット符号付き: 100 + 50 でビット 10010110 が得られる。何が起きたか?
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
150 は 127 よりも大きいため、結果は範囲外となり、ビットは −106 にデコードされる。符号則がこれを検知する。
8ビット符号付き数値 0101 1010 (90) と 0100 0110 (70) を加算します。何が起こりますか?
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
和は $10100000$ で、これは −96 に復号される。符号が両方とも正または負で、一方だけが異なる場合はオーバーフローであり、このケースには持ち出しは全く発生していない。
Three common slips
- Reading two's complement as unsigned. $10011100$ is 156 or −100; the interpretation decides, not the bits.
- Forgetting the lopsided range. −128 fits in 8 bits; +128 does not.
- Calling every carry-out overflow. Only the sign rule (or the carry mismatch at the top bit) decides.
最上位ビットからの持ち出しは、常に符号付きオーバーフローを意味する。
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
例えば、$-1 + 1$を8ビットで表すと Carry-out が生じ、正しい結果0となる。オーバーフローは符号による判断、または最上位ビットへのCarry-inとCarry-outが異なることにより決定される。
Recap
- Binary value = sum of the weights under the 1s; hex = groups of 4 bits.
- Two's complement: invert and add 1. One 8-bit pattern, two readings:
| 8 bits | Unsigned | Two's complement |
|---|---|---|
| Range | 0 to 255 | −128 to +127 |
| 10011100 (hex 9C) | 156 | −100 |
| 11111011 | 251 | −5 |
- Overflow: like signs in, unlike sign out.
何が問題でしたか?この内容はサイトの運営チームだけが確認します。