0
what does '>>' operator mean?
Recently on codes of other people I saw >> operator. Couldn't understand it...something like bitwise right or something like that...please tell me what does this operator do?
2 odpowiedzi
+ 2
well, bitwise operator is used to perform manipulation of data at bit level. if you use right shift it will shift the bits toward right of given number.
ex.
int a = 6;
int b = a >> 2;
4 2
// 6 in bit. 0 0 0 0 1 1 0
//shift 2 bit to the right
1
//result. 0 0 0 0 0 0 1
so b = 1
0
Additionally, you must know that right shift is equivalent to divide (integer division) by 2 raised to the power of numbers of bits and left shift (<<) conversely multiply by 2 power number of bits shifted...
As in decimal, removing digit a right divide (integer division) by 10 (power to numbers of digit), and conversely appending 0 digit(s) to the right multiply by 10 (power to numbers of digits):
1234 => 12 <=> 1234 // 100 (10^2)
42 => 4200 <=> 42 * 100