How do I convert a signed decimal integer to 16-bits binary in Python? bin() function is pretty basic and just adds a "-" before the number.
My requirement is: Suppose we have a number -4, then output should be 1000000000000100. That is, MSB is sign bit and rest magnitude bits.
I have tried the common masking technique but it gives 2's complement and extension of 1's in the significant bits. For example, print(bin(-7 & 0b1111111111111111).replace("0b","")) Output: 1111111111111001