The complement is often used to represent negative numbers for easy calculation.
Positive numbers and zero complement are themselves, and the complement method of negative numbers is as follows:
Binary subtraction can be implemented by adding the complement of the subtracted number to the subtracted number.
**<MethodOne> Direct Method**
$$(N)_{COMP}=\begin{cases}N&\text{N is a positive number}\\2^{n}-N& \text{N is a negative number} \end{cases}$$
When the sign bit is zero (positive number), the complement is the same as the source code. When the sign bit is 1 (negative number), the complement is $2^{n}-N$.
**<MethodTwo> Observation Method**
If you want the complement, you can find the inverse first.
$$(N)_{INV}=\begin{cases}N&\text{N is a positive number}\\(2^{n}-1)-N& \text{N is a negative number} \end{cases}$$
That is, except for the sign bit, 0 changes to 1, and 1 changes to 0.
Then add 1 to the whole complement to get the complement~
## Common coding
### DCB
That is, the 8421 constant weight code. When DCB is displayed as a decimal number, 6 must be added to each Invalid bit (>9).
### Signed Numbers
8 bits are used, the leftmost bit represents the sign, and the remaining 7 bits represent the value.
## Mid-term summary
### First week-first acquaintance with digital telephony
- The analog quantity is too complicated to conform to human thinking
- Non-linear devices such as triode and MOS tube provide the device basis for the magic speed
- Because analog electricity is too difficult, we have to learn math electricity
**Some points**
- TTL means transistor logic circuit, composed of various transistors and resistors, and is characterized by fast speed
- 0-0.8V in TTL is low level, 2-5V is high level
- Conversion between binary and decimal (integer/decimal)
- LSB(Least Significant Bit)/MSB(Most S B)
### Second week-Number system
- 1's Complement
- 2's Complement
- Sometimes the binary is too long to use, which makes hexadecimal very convenient
- Hexadecimal is similar to binary mnemonic, if you observe `1100 0101`, you can write `C5` directly
- BCD uses a hexadecimal number to represent a decimal number
- BCD is in line with human thinking habits, but it causes a great waste of resources
- BCD four arithmetic, I think it’s best to convert to decimal and then convert it back. Anyway, it’s very convenient
- Computer BCD addition adopts +6 carry method
- When storing numbers, the leftmost digit is the sign bit
- Negative numbers are stored using one's complement ([chestnut][1])
- 1 byte signed number range `-128-127`
- Reasonably design the number of storage bits and be careful of overflow