Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.27 KB | None | 0 0
  1. 111111...1
  2.  
  3. 011111....1
  4.  
  5. rightShiftVal(int val) {
  6. if (int < 0) {
  7. int res = ~val; //not the value.
  8. res = res >> 1; //do the right shift (the direction of the shift is correct).
  9. res = ~res; //Back to twos complement.
  10. return res;
  11. }
  12. return val >> 1;
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement