I neeed to convert a np array of integers to 12 bit binary numbers, in an array format. What would be the best way to go about doing so?
I've been a bit stuck so any help would be appreciated. Thanks!
Here is what I have to convert an integer to binary:
def dec_to_binary(my_int):
"""
Format a number as binary with leading zeros"""
if my_int < 4096:
x= "{0:12b}".format(my_int)
return int(x)
else:
return 111111111111
'1'and'0'actually use much more memory (12 bytes) than 16 bit ints (2 bytes).