Arm/saturate

From ASMBits

Sometimes when doing arithmetic, it is better to "saturate" (or clamp) numbers that overflow to the maximum possible value rather than wrap around.

Write a function that will convert an unsigned 32-bit number to 16 bits. If the 32-bit number is too big to fit, saturate (or clamp) the output to the maximum possible unsigned 16-bit value.

unsigned short saturate(unsigned int n);


Expected solution length: Around 3 lines.

Sample Input

0x12345

Sample Output

0xffff

Write your solution here

Upload a source file...