Ruby: Conversão binária em Ruby

Palavras-chave: Ruby, conversão, binária

É muito fácil fazer conversões de uma string binária para um número e vice-versa em Ruby:

irb(main):001:0> i = "11111111".to_i(2)
=> 255
irb(main):002:0> i.to_s(2)
=> "11111111"

Os métodos to_i e to_s, com a base desejada (2), fazem o trabalho perfeitamente.

This entry was posted in Ruby. Bookmark the permalink.

2 Responses to Ruby: Conversão binária em Ruby

  1. หนัง says:

    Hi there Dear, are you really visiting this site daily,
    if so after that you will absolutely obtain nice knowledge.

  2. First off I want to say awesome blog! I had a quick
    question which I’d like to ask if you do not mind. I was interested
    to know how you center yourself and clear your thoughts before writing.

    I’ve had a hard time clearing my thoughts in getting my
    thoughts out there. I do enjoy writing however it just seems like the first 10 to 15
    minutes are usually wasted just trying to figure out how to
    begin. Any recommendations or hints? Thank you!

Leave a Reply

Your email address will not be published. Required fields are marked *