0

I basically need to get user input:

gets.chomp("input?")

And then to convert the given input to binary.

That's the part I don't get. :(

8
  • What do you mean convert to binary? Convert to a binary int representation? Pack into some kind of byte stream? Commented Jun 19, 2012 at 23:19
  • or rather, "Hello!" would be 01001000 01100101 01101100 01101100 01101111 00100001 Commented Jun 19, 2012 at 23:39
  • Exact duplicate: stackoverflow.com/questions/143822/… Commented Jun 19, 2012 at 23:41
  • 2
    @CodeGnome No. It is not a duplicate. Commented Jun 19, 2012 at 23:41
  • 1
    your two questions so far look suspiciously like school homework and should be tagged as such Commented Jun 20, 2012 at 2:53

1 Answer 1

1

Try this.

a = gets.chomp
puts a.each_byte.map {|y| sprintf "%08b", y}.join " "
Sign up to request clarification or add additional context in comments.

2 Comments

This is unsatisfactory: it doesn't zero pad, or space, so you get a stream of digits, but it's impossible to reassemble the original meaningfully.
@Len you are almost a ruby god

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.