The story of cover: the enigma machine made by Alan Turing
Logical operation
Boolean type
Boolean is used for describing authenticity of things in computer, which only includes two status: True
and False
, so it’s really easy to present it in computer.
We can only use one bit to present boolean value:
Boolean  Bit value  Meaning 

True  1  The condition is meeted or the thing is true 
False  0  The condition is unmeeted or the thing is false 
Boolean is a data type in programming rather than a data type in daily use(they are all called data type, but different meaning). That’s why I put it here rather than last post.
All logical operation is operation works on boolean value(single bit value).
NOT operation
NOT operation only needs one boolean involving.
It means the opposite thing: not true means false, and not false means true, which is easy to understand.
Before NOT  After NOT 

1 (true)  0 (false) 
0 (false)  1 (true) 
AND operation
AND operation needs two boolean involving.
Only you can get True when two things are True at same time.
Boolean 1  Boolean 2  Result 

0 (false)  0 (false)  0 (false) 
1 (true)  0 (false)  0 (false) 
0 (false)  1 (true)  0 (false) 
1 (true)  1 (true)  1 (true) 
OR operation
OR operation needs two boolean involving as well.
Only you can get False when two things are False at same time.
Boolean 1  Boolean 2  Result 

0 (false)  0 (false)  0 (false) 
1 (true)  0 (false)  1 (true) 
0 (false)  1 (true)  1 (true) 
1 (true)  1 (true)  1 (true) 
XOR operation
XOR operation needs two boolean involving as well.
 When two things are the same gets False
 When two things are different gets True
Boolean 1  Boolean 2  Result 

0 (false)  0 (false)  0 (false) 
1 (true)  0 (false)  1 (true) 
0 (false)  1 (true)  1 (true) 
1 (true)  1 (true)  0 (false) 
Shift operation
Logical shift operation
Shifting the whole bit sequence to left or right
Nonloop logical shift
In this case, after the shift, the overflow parts will be ignored, and the new space will be filled by zero.
Shifting a 8length bit sequence for 1 bit


Loop logical shift
In this case, you can imagine the whole bit sequence is a circle. After the shift, nothing will be lost but the order.
Shifting a 8length bit sequence for 1 bit


Arithmetic shift operation
Shifting the bit sequence including sign to left or right. In other words, the bit sequence needs shift is a number with sign. So it can only be used on bit sequences presenting numbers.
Shift to Left
In this operation, the process of shift to left and shift to right have a few of differences.
The content after shift will cover the sign, and new spaces will be filled by zero. If the sign has changed in the shift, which means the overflow happens.




Shift to right
All data will move to right, excepting the sign. The empty space will be filled by sign and the surpassed tail will be ignored.


Arithmetic operation
At this place, we only talk about addition and subtraction.
Between two’s complements
It’s the most simple situation. You can just calculate it like decimal numbers, the only difference is you need to ignore the last column carry if exists.
For substraction, you can use the two’s complement to make the it becomes addition.






Between absolute values with sign
In this case, we use sign and absolute value to present a number rather than two’s complement.
Here are the steps:
For easier illustration, A
means the first number, and B
means the second number.
 If the operation is substraction, making
B
opposite, so that substraction becomes addition.  XOR operation to the signs of
A
andB
, checking whether they have the same sign.  If the result is 0 means they have the same sign, we can add the absolute value directly and the sign won’t change after calculation. If any overflow happens, the result is wrong.
 Otherwise, the sign is different, calculating the two’s complement of the absolute value of
B
, and adding it to the absolute value ofA
, and the sign is the same as which number has bigger absolute value. If
A
has bigger absolute value, the sign will be the same asA
and we can ignore the overflow  If
B
has bigger absolute value, the sign will be the same asB
and getting the two’s complement of the result
 If






Between real number
For easier illustration, A
means the first number, and B
means the second number.
 If A or B is zero, finishing the operation, and the result is the other number
 If it’s a substraction, change the sign of B, so that substraction becomes addition
 Reverse standardization: add 1 to the head of fraction parts of
A
andB
 Adjusting the exponent, making the exponent of
A
andB
be the same.  It includes 2 situations:
 the sign of A and B are the same: keep the sign and add the fraction
 the sign of A and B are different: sign is which has bigger fraction, and bigger fraction minus smaller one.
 Standardization and get the result



