How to tell if a 32 bit int can fit in a 16 bit short
问题 Using only: ! ~ & ^ | + << >> I need to find out if a signed 32 bit integer can be represented as a 16 bit, two's complement integer. My first thoughts were to separate the MSB 16 bits and the LSB 16 bits and then use a mask to and the last 16 bits so if its not zero, it wont be able to be represented and then use that number to check the MSB bits. An example of the function I need to write is: fitsInShort(33000) = 0 (cant be represented) and fitsInShort(-32768) = 1 (can be represented) 回答1: