DEV Community

Junichi Kajiwara
Junichi Kajiwara

Posted on

Reading the message written in binary for Ruby 25th Anniversary using by mruby.

Hello,I found this tweet.

I wonder what is written and I tried to read using by mruby.

Code

It seemed that the binary code is ascii code.

I wrote the decode binary code in mruby.

rawData = "01001001 00100000 01001100 01101111 01110110 01100101 00100000 01010010 01110101 01100010 01111001 00101110"
puts rawData.split(" ").map{|c| c.to_i(2)}.map{|c| c.chr("UTF-8")}.join
Enter fullscreen mode Exit fullscreen mode

Result

bin/mirb 
mirb - Embeddable Interactive Ruby Shell

> rawData = "01001001 00100000 01001100 01101111 01110110 01100101 00100000 01010010 01110101 01100010 01111001 00101110"
 => "01001001 00100000 01001100 01101111 01110110 01100101 00100000 01010010 01110101 01100010 01111001 00101110"
> puts rawData.split(" ").map{|c| c.to_i(2)}.map{|c| c.chr("UTF-8")}.join
I Love Ruby.
 => nil
> 
Enter fullscreen mode Exit fullscreen mode

I noticed that Ruby has putc, but mruby didn't have.

epilogue

to tell the truth,I first time I wrote decode code in JavaScript.
but I thought this is a chanse to learn mruby,so I wrote this in mruby.

Link

Top comments (0)