string - Converting to binary in MATLAB and Python -


i have matlab code trying convert python.

in matlab code takes string , converts double, binary.

x = dec2bin(double(string), 8); 

now, string has numbers, letters, decimal points, , commas. matlab has no problems converting this.

is there in python can this?

i've tried using bin(), changing string float first, various numpy options like:

x = numpy.base_repr(string, 2, 8) 

and

numpy.binary_repr() 

you can with:

>>> string = "foo" >>> res = [bin(ord(i)) in string] ['0b1100110', '0b1101111', '0b1101111'] 

the same example in matlab gives same result:

>>> dec2bin(double('foo'), 8) 01100110 01101111 01101111 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -