Convert int to 16 bit unsigned short

python

Solution

The classical way is to extract the relevant bits using a mask:

>>> hex(0x19c6acc6 & 0xffff)
'0xacc6'

Problem

I want to trim an integer to 16 bit word (unsigned short) in Python. Something like following does not work ``` word = array("H") word.insert(0,0x19c6acc6) ```

Original source