I have a specification which outlines how instructions should be sent over serial.

Currently I am crafting the packets that will go over the connection.

One segment of the packet, requires a 32-bit (4 byte) binary number. 
The first 31-bits are 'data' and the last bit is merely a flag.

So, The max decimal number that could fit in data is: 2147483647 (2^31). Data could never be bigger than this, Cool!

My problem, is how do I go about encoding the data to 31-bits binary, then setting the final bit to enable the flag?

Say my data is `7AAAAAAA` what is the desirable way of converting this to 31 bit binary then adding 1 or a 0 to the end?

**Edit - I'm Using Python 3.4**