# How PSOC™ Creator executes right shift of signed integer – KBA236289

## How PSOC™ Creator executes right shift of signed integer – KBA236289

Employee
Employee

Community Translation: PSOC™ Creatorが符号付き整数の右シフトを実行する方法 – KBA236289

Version: **

Positive signed integer

In PSoC™ Creator, an ‘N’ bits right shift operation of a positive signed integer number remains the MSB (the sign bit of the number’s binary code) unchanged and shifts the number to the right by ‘N’ bits (bits of the number’s binary code). Therefore, the vacated bit positions by the shift operation are zero-filled.

Negative signed integer

In PSoC™ Creator, an ‘N’ bits right shift operation of a negative signed integer number remains the MSB (the sign bit of the number’s complement binary code) unchanged and shifts the number to the right by ‘N’ bits (bits of the number’s complement binary code). Therefore, the vacated bit positions by the shift operation are one-filled.

For example:

A 4-bit right shift of -100 (decimal), a 32-bit negative signed number.

Original binary code of -100:                                                          0b 10000000   00000000   00000000   01100100
Complement binary code of -100:                                                0b 11111111   11111111   11111111   10011100
4 bits right shift of the above complement binary code:    0b 11111111   11111111   11111111   11111001
Original binary code after 4 bits right shift:                              0b 10000000   00000000   00000000   00000111
Therefore, the result of the 4-bits right shift of -100 (decimal, 32-bit) is -7 (decimal, 32-bit).

134 Views