Is there a way to read binary data in JavaScript?

user41814 picture user41814 · Nov 29, 2008 · Viewed 74.9k times · Source

I would like to inject binary data into an object in JavaScript. Is there a way to do this?

i.e.

var binObj = new BinaryObject('101010100101011');

Something to that effect. Any help would be great.

Answer

Greg picture Greg · Nov 29, 2008

You can use parseInt:

var bin = parseInt('10101010', 2);

The second argument (the radix) is the base of the input.