Hex to bin


In [8]:
hexdata = "fff39ced"

In [11]:
scale = 16 ## equals to hexadecimal
num_of_bits = 32

In [13]:
bindata = bin(int(hexdata, scale))[2:].zfill(num_of_bits)

In [14]:
bindata


Out[14]:
'11111111111100111001110011101101'

In [15]:
len(bindata)


Out[15]:
32

In [18]:
type(bindata)


Out[18]:
str

Decimal to binary


In [7]:
decdata = "728"

In [8]:
scale = 10
num_of_bits = 32

In [9]:
bindata = bin(int(decdata, scale))[2:]
#.zfill(num_of_bits)

In [10]:
bindata


Out[10]:
'1011011000'

In [11]:
int(bindata)


Out[11]:
1011011000

In [12]:
bindata[0]


Out[12]:
'1'

In [13]:
int(bindata[0])


Out[13]:
1

In [14]:
import numpy as np

In [15]:
bindataarray = np.array([[int(e) for e in bindata]])

In [21]:
bindataarray


Out[21]:
array([[1, 0, 1, 1, 0, 7, 6, 0, 0, 0]])

In [20]:
bindataarray[:,5:7] = np.array([7,6])

In [22]:
range(5,16)


Out[22]:
[5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]

In [ ]: