Hi, I have simple lesson when I try to use shift operator for my program.When I visit a site, I found calculation from shift operator in arithmetic operator.
We know there is two type of shift operator, shift left and shift right.Shift left to move some bit to left,shift right to move some bit to right.
8 >> 3,it's mean move 3 bit to right, so the result is 1 in integer.In binary it's mean like this :
8 in binary is 1000, after that move three bit to right become 1 in binary, in decimal the result is 1.
There is another alternative for calculate above operation, look at this, for the shift right operator, x >> y mean x / 2 ^ y, and for the shift left operator, x << y mean x * 2 ^ y.
For the above explanation we can see like this.
8 >> 3 equal with 8 / 2 ^ 3 and 8 << 3 equal with 8 * 2 ^ 3.
We know there is two type of shift operator, shift left and shift right.Shift left to move some bit to left,shift right to move some bit to right.
8 >> 3,it's mean move 3 bit to right, so the result is 1 in integer.In binary it's mean like this :
8 in binary is 1000, after that move three bit to right become 1 in binary, in decimal the result is 1.
There is another alternative for calculate above operation, look at this, for the shift right operator, x >> y mean x / 2 ^ y, and for the shift left operator, x << y mean x * 2 ^ y.
For the above explanation we can see like this.
8 >> 3 equal with 8 / 2 ^ 3 and 8 << 3 equal with 8 * 2 ^ 3.
No comments:
Post a Comment
Your Comment