Shift operation in C #
In the computer, the negative numbers in the signed type are stored in the form of binary complement. How can we obtain the decimal value of the binary number in the form of this complement?
1) The bitwise (including the sign bit) of the number in the binary complement form is reversed, and then 1 (binary operation ).
2) Calculate the decimal value of the obtained number as an unsigned number, and add a symbol before it.
========================================================== ==========================================================
// 1: 0 0000000 00000000 00000000 00000001
//-1: 1 0000000 00000000 00000000 00000001 (original code)
//-1: 1 1111111 11111111 11111111 11111111 (Supplemental code)
//-2: 1 0000000 00000000 00000000 00000010 (original code)
//-2: 1 1111111 11111111 11111111 11111110 (Supplemental code)
Int num =-2;
Int ret = num> 1;
Console. writeline (RET );
// For the shift operation in C #, it is for the "binary storage as a whole" of the number in the computer.
//
// <(Left shift) indicates the entire left shift. All spaces that are empty on the right are filled with zeros.
//> (Right shift): 1. Number of unsigned characters
// Shifts the entire right, and all the spaces empty on the left are filled with zeros.
// 2. Number of symbols
// Shifts the entire right. All the null bits on the left fill in the signed bits of this number.
//
// The result is the binary number.
========================================================== ==========================================================
Shift operations in javascript:
<(Left shift)> (right shift): If it is an unsigned number, it doesn't matter. Move it as a whole. If there is a number of symbols, the symbols do not move.
>>> (Right shift of the unsigned number): All values are considered as unsigned numbers, and the empty bits on the left are filled with 0. (Returns the number of unsigned types)