Advertisement
Guest User

Untitled

a guest
Oct 4th, 2015
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. x = x >> 1;
  2.  
  3. x = x / 2;
  4.  
  5. -5 / 2 = -2
  6. -5 >> 1 = -3
  7.  
  8. x = x / 2 + 5;
  9. x = x >> 1 + 5; // not the same as above
  10.  
  11. int div2signed(int a) {
  12. return a / 2;
  13. }
  14.  
  15. movl %edi, %eax
  16. shrl $31, %eax
  17. addl %edi, %eax
  18. sarl %eax
  19. ret
  20.  
  21. int shr2signed(int a) {
  22. return a >> 1;
  23. }
  24.  
  25. sarl %edi
  26. movl %edi, %eax
  27. ret
  28.  
  29. q = i >> n; is the same as: q = i / 2**n;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement