2-5 Sign Extension

By "sign extension," we mean to consider a certain bit position in a word to be the sign bit, and we wish to propagate that to the left, ignoring any other bits present. The standard way to do this is with shift left logical followed by shift right signed. However, if these instructions are slow or nonexistent on your machine, it may be done with one of the following, where we illustrate by propagating bit position 7 to the left:



The "+" above can also be "-" or "." The second formula is particularly useful if you know that the unwanted high-order bits are all 0's, because then the and can be omitted.