Posted By

jimbobmcfred on 09/28/10


ruby binary

Versions (?)

Ruby binary string conversion

 / Published in: Ruby

Quick conversion from a string of binary into ascii, and back again.\r\nUse B* for MSB and b* for LSB first.

  1. puts "011010000110010101101100011011000110111100100000".scan(/.{1,8}/).collect{|x| x.to_i(2).chr}.to_s.inspect
  2. puts "hello there".split(//).collect{|x| x.unpack("B*")}.to_s.inspect

Report this snippet  

You need to login to post a comment.