C programming language syntax Review

10 transfer binary decimal

Use short division

The original code, anti-code and complement

The computer is used to store data complement, why should the introduction of anti-code and complement it?

  • Original code: the digital computer in the form of binary, called the number of machines, with the sign bit is binary, for example: numbers 3 and -3, the binary representation of 00000011 and 10000011, respectively, the most significant bit, i.e., the leftmost position is the sign bit, n represents 0, 1 denotes a negative.
  • Anti-Code: positive anti-code the same as the original code, inverted negative which is based on the original code, change the sign bit, the remaining bits inverted. That is, 1 becomes 0, 0 becomes 1.
  • Complement: complement source with the same certificate, negative complement is added on the basis of a radix.
Decimal Original code Inverted Complement
3 00000011 00000011 00000011
-3 10000011 11111100 11111101
9 00001001 00001001 00001001
-9 10001001 11110110 11110111

In simple terms the introduction of anti-code it is to make the foundation of computer circuit design easier, because adding a negative number is equivalent to subtracting a positive number, so you can just let the computer do the addition can be. But this is obviously there drawbacks, for it is the number 0, there will be two coded representation 0: 00000000 and 10000000 and signed 0 is meaningless. Therefore, the introduction of complement, complement positive numbers is the original code itself, negative anti-code complement +1. -0 decimal notation, the original code: 10000000, anti-code: 11111111, Complement: overflow, corresponding to -128. Therefore there is no original code -128 and inverted Thus, by actually complement -128 -0 represented. This would solve the problem of multiple representation 0. But also to represent a plurality of digital -128, it is why the range of 8-bit binary number represented by the [-128] to [127]

Bitwise Operators

  • & Bitwise AND: two numbers involved in computing, for each corresponding phase and binary, i.e., are both 1 was 1, and 0 otherwise.
如9&5:
00001001
00000101
00000001  计算结果,最终为1
  • | Bitwise or: two numbers involved in computing, for each corresponding phase, or binary, as long as there is a 1, compared to 1.
如4|2
00000100
00000010
00000110 计算结果,最终为6
  • ^ Bitwise XOR: involvement of two operands, each corresponding phase, or binary, i.e., corresponding to each different digital was 1.
如4^2
00000100
00000010
00000110 计算结果,最终也为6

Shift operation

Binary whole left or right movement, lack of movement of the left portion corresponds to 0. complement multiplication, division corresponds to the right. The decimal number 5 << 2. In binary notation 00000101 00010100 is moved leftward 2, multiplied by the equivalent of 2 5 * 2.


Guess you like

Origin www.cnblogs.com/falcon-fei/p/11060188.html