Ruby binary string conversion

/ Published in: Ruby
Save to your folder(s)

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

Copy this code and paste it in your HTML
  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


RSS Icon Subscribe to comments

You need to login to post a comment.