title: Can you control what a bitwise right shift will fill in C?
body: <p>As far as I know when you use a left shift bitwise operator in C it's guaranteed that the vacant bits will be filled with 0s. However, I've read that the right shift is implementation-dependent, meaning in some machines the vacant bits will be filled with 0s, in others they will be filled with 1s.</p>
  
  <p>I am using the right shift in a program, and indeed my machine is filling the vacant bits with 1s. Problem is I would need it to fill with 0s instead.</p>
  
  <p>Is there a way to force 0s to be used on right shifts?</p>
  
  <p>One solution would be, after the right shift is applied, to create a mask like 011111111 and then apply a bitwise AND, which will change the leftmost 1 that was inserted to a 0. </p>
  
  <p>But this is cumbersome and wastes time. If there was a way to tell my machine to fill right shifts with 1s it would be much easier.</p>
  
  <p>Thanks</p>