What’s an arith shift?

Print anything with Printful



Arithmetic shifts can multiply or divide numbers by the base of the numbering scheme. Binary numbers are commonly used and can be signed or unsigned. Shifts are faster than regular multiplication and division, but have limitations. Computers use a shift unit or register.

An arithmetic shift is a way of multiplying or dividing numbers. Arithmetic shifts are usually performed on binary numbers. The concept, however, is applicable to any numbering scheme.

The following is an example using decimal numbers that have ten as a base. When 250 is arithmetically shifted to the left, the resulting number is 2500, which is 250 multiplied by ten. When 250 represented using 4 digits such as 0250, is shifted arithmetically to the right, the resulting number is 0025, which is 250 divided by ten. So it is more correct to say that an arithmetic shift is a way of multiplying or dividing numbers by the base of the number pattern.

Binary numbers have 2 as a base; they are represented using 0 and 1 and can be signed or unsigned. In an arithmetic shift left, the numbers are shifted one space to the left and the zero is placed to the right. In an arithmetic right shift, the numbers are shifted one space to the right while keeping the leftmost number to the left. In general, a move can be for “n” spaces.

In unsigned binary numbers, each position is a power of 2, so binary 1 is decimal 1, binary 10 is decimal 2, binary 100 is decimal 4, and so on. So 0110 is decimal 6. When an arithmetic shift to the left is performed, the resulting number is 1100 which is decimal 12. When an arithmetic shift to the right is performed the resulting number is 0011 which is decimal 3.

Since numbers can be both positive and negative, signed binary numbers are used where the leftmost bit is 0 for a positive number or zero and 1 for a negative number. Therefore, for 4-bit numbers, 0111, which is decimal 7, is the largest positive number. The pattern most often used for negative numbers has 1111 as decimal -1 and this goes all the way down to 1000, which is decimal -8.

For example, an arithmetic left shift on 1101, which is decimal -3, returns 1010, which is decimal -6. An arithmetic right shift on 1010, which is decimal -6, results in 1101, which is decimal -3. Note that the leftmost bit is kept.
An arithmetic shift does not always correspond to multiplication and division for every number in the number pattern. There are limitations at both ends of the number scheme. For example, a left shift of 0111, decimal 7, gives decimal -2, and a right shift of 1111, decimal -1, gives decimal -1.
A shift arithmetic has an inherent simplicity, and a shift is much faster to perform than regular multiplication and division. So computers support this using a relatively simple mechanism called a shift unit or shift register. Experienced programmers use this as long as the limitations mentioned above are avoided or attended to.




Protect your devices with Threat Protection by NordVPN


Skip to content