Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 111111...1
- 011111....1
- rightShiftVal(int val) {
- if (int < 0) {
- int res = ~val; //not the value.
- res = res >> 1; //do the right shift (the direction of the shift is correct).
- res = ~res; //Back to twos complement.
- return res;
- }
- return val >> 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement