5
\$\begingroup\$

This morning I've seen this on Twitter: http://mynewtechworld.tumblr.com/post/135545896048

I case that somebody can't see the image:

I
01101100
01101111
01110110
01100101
you.

Just for fun I wrote this binary to ascii-converter in JavaScript:

var chars = [
  'I ',
  0b01101100,
  0b01101111,
  0b01110110,
  0b01100101,
  ' you.'
];

var result = chars.reduce(function(previous, current) {

  if (!isNaN(current)) {
    current = String.fromCharCode(current.toString());
  }

  return previous + current;
}, '');

My complete implementation on CodePen

\$\endgroup\$
1
  • \$\begingroup\$ Welcome to CodeReview, a fine first question :) \$\endgroup\$ Commented Dec 20, 2015 at 10:49

1 Answer 1

1
\$\begingroup\$

I suggest splitting:

  • Converting binary to ascii
  • Concatenating

After defining binaryToNumber and add. the final code will look much simpler:

var result = chars.map(binaryToNumber).reduce(add)
\$\endgroup\$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.