Hello there, hope you are all doing well.
I am working on a little assignment right now. I have a string of a binary number, which I need to convert to decimal. I converted the string to a numpy array and then tried what I saw on this link's answer:
Convert binary (0|1) numpy to integer or binary-string?
However, since my array has a size of 54, the solution is not working correctly, I am getting negative results whereas the correct value is a very large positive number.
# data_binary = [0 1 1 1 0 1 1 1 0 1 0 1 0 0 0 0 0 0 1 0 1 0 0 1 1 0 1 0 0 1 1 0 1 0 1 1 1 0 0 0 0 0 1 0 1 1 1 1 1 1 1 1 1 1]
data_decimal = data_binary.dot(1 << np.arange(data_binary.size)[::-1])
For example, the decimal equivalent of the data_binary in this instance is "8395915512384511", however my script calculates it as "1773014015".
Is there any method which you can suggest me to use to achieve my goal? Thank you so much in advance!