PHP original code, anti-code, complement introduction
Original code:
Is "The original binary code", in fact, we can understand the decimal conversion to binary after the resulting character code. The original code is understandable in numbers. But in the actual computer running process, but often do not use the original code, so there are anti-code, complement the problem.
On this basis, the rule: the first bit of a binary number is the sign bit, 0 for positive numbers, and 1 for negative numbers.
For example: (all 8-bit examples):
7:00000111
-7:10000111
Anti-code:
The inverse code of a positive number is itself.
The inverse of a negative number is the non-symbolic part of the original code, each bit reversed.
Example:
7:00000111
-7:11111000
Complement:
The complement of a positive number is its own
Negative number of the anti-code, the sign bit unchanged, each of the remaining after the inverse, the whole plus 1
Example:
7:00000111
-7:11111000+1 = 11111001
Addition Operation:
650) this.width=650; "src=" http://s2.51cto.com/wyfs02/M00/75/FB/wKiom1ZGpkSzwieHAAAmNAu3pl8921.jpg "title=" 01.jpg "alt=" Wkiom1zgpkszwiehaaamnau3pl8921.jpg "/>
Subtraction Operations:
650) this.width=650; "src=" http://s2.51cto.com/wyfs02/M02/75/F8/wKioL1ZGptTS7eVOAABYypLOJI0342.jpg "title=" 01.jpg "alt=" Wkiol1zgptts7evoaabyyploji0342.jpg "/>
Summarize:
1: Data is performed in the internal CPU by complement
2: The original code, anti-code, the complement of the conversion process is the internal work of the system, and the conversion of the symbol bit unchanged
3: When using the complement operation, the sign bit participates in the operation (that is, as a normal bits number of operations)
Managing the switching state of a set of things (data)
Switch status: It is a kind of data, it only 2 values available: true,false,1,0, open, off ...
A group of things refers to: any possible occurrence of multiple data states
We assume that there are 5 light switches that need to be managed:
1: Determine the status of each lamp: on, off;
2: Can be specified to open any one bulb
3: Can be specified to turn off any bulb
Set the premise: these 5 bulbs have a definite order, we will set 5 variables (constants are actually OK)
Assuming that the position of the 1-5 bulbs is from right to left-the number of digits corresponding to the number
First bulb: $d 1 = 1; 00000001
Second bulb: $d 2 = 2; 00000010
Third bulb: $d 3 = 4; 00000100
Fourth bulb: $d 4 = 8; 00001000
Fifth bulb: $d 5 = 16; 00010000
Then the total state of all the bulbs can be described using a variable:
If $state = 7; 00000111 means first, two, three light bulbs.
If $state = 9; 00001001 means first, four light bulbs
if $state = 13; 00001101 means first, two, four light bulbs.
Determine the switching of a light bulb:
$s 1 = $state & $DN//here n means any one between 1-5
If $s1 > 0, it indicates that the bulb is lit, otherwise
To open the specified light bulb:
$state = $state | $DN; Here n means any one between 1-5.
To turn off the specified lamp:
$state = $state & ~ $DN; Here n means any one between 1-5.
PHP original code, anti-code, complement introduction