DEV Community

Junichi Kajiwara
Junichi Kajiwara

Posted on

2

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

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay