Well, -9 isn't 1001010, but we can explore that another time.<p>The real help would be if you showed what you've tried.  However:<p>How can you extract the rightmost (least significant) 3 bits of a number <i>x</i>?<p>How can you move the bits in a number to the left (make them more significant)?<p>How can you turn off some bits in a number?<p>Can you puzzle out how these questions/answers can be glued together to do what you want?<p>Have you tried doing it by hand on paper?<p>Here:<p><pre><code>   x = 1010101010101
   p = 4
   n = 5
   y = 11111111
</code></pre>
Show us what you actually need to do, step by step.<p>PS: This probably isn't the forum to have a tutorial on such questions, and I'm going off line in a few minutes.  If no one else answers your questions, email me.<p>PPS: Where does this question come from?  What resources do you have?