Alterna · учебный материал
Presentation of whole numbers
Direct, reverse, extra codes, congestion simulator, int8/uint8.
Что в этом материале
- Direct code (sign-magnitude)
- Reverse code (ones' complement)
- Additional code (two's complement) is a standard
- Int8/uint8 overcrowding simulator
- Comparisonr of Three Codes
- Mini-test: 5 questions
Содержание и основные понятия
Back to the table of contents
Alterna · Chapter 30 · page 30.1
Presentation of whole numbers
Three codes, banding, overcrowd simulation, and comparing all codes at once.
Negative wholes stored in
additional code
This allows the processor to use one ALU scheme to add and subtract. Understanding these codes is the key to the tasks of the EGE No.14.
GEF
PIF
EGE No. 14
01
Direct code (sign-magnitude)
The senior bit is a sign (0 = "+", 1 = "-".
Examples in 8 bits
+5 =
0
0000101
−5 =
1
0000101
+0 =
0
0000000
−0 =
1
0000000
Problem
Two zeros: +0 and -0. The addition requires an analysis of the signs.
not used
.
02
Reverse code (ones' complement)
For the positive, as a straight line. For the negative,
Invert all bits
(including the sign).
Examples in 8 bits
+5 =
0
0000101
−5 =
1
1111010 (инверсия 00000101 = 11111010)
+0 =
0
0000000
−0 =
1
1111111
Where applicable
Historically used in some Mainframe's; today it is rare to see it in online protocols (CRC, reference amounts).
03
Additional code (two's complement) is a standard
For the positive, as a straight line. For the negative:
We're taking the number module in the binary.
Invert all bits.
Add 1.
Example: -13 in 8 bits
|13| = 00001101
Инверсия: 11110010
+1:
11110011
🔢
Interactive 1: Bit Visualizer — Number in Supplementary Code
Kick the bats to change them.
Value:
7
6
5
4
3
2
1
0
Введи число или кликни по битам.
04
Int8/uint8 overcrowding simulator
Turn the arrow around, you see what happens when you go beyond range.
⚠️
Interactive 2: Round Scale — Overcrowding
Type
−128
127
0
Нажимай +1 и −1, чтобы увидеть, как числа «оборачиваются» по кругу.
Important for the EGE
When overfilling in8: 127 + 1 = -128 (not 128 as in uint8).
architectural decision
The processor is fully compatible with the ALU operations.
05
Comparisonr of Three Codes
Enter any number -- get all three codes right with the color markings.
⚖️
Interactive 3: Direct, Inverse and Additional - One Window
Number (int8):
—
Press "Equip"
Key differences
Direct code:
Senior bit = sign, rest = number module.
Reverse code:
Invert all bits (including the sign) Two zeros: +0 and -0.
Additional code:
1. One zero. Subtraction = addition. Standard of modern CPU.
🎯
Mini-test: 5 questions
XP: 0 / 100
🧩
Quick test on the subject
Five questions, 20 XP for every correct answer.