module RadixEncoding::Encoding::Bits

Public Instance Methods

bits_for(bytes) click to toggle source
# File lib/radix_encoding/encoding/bits.rb, line 8
def bits_for(bytes)
  bytes.
    map do |byte|
      byte.
        # Convert the byte (a number) to a string with its binary form
        to_s(2).
        # Pad the result with leading zeros to represent all the bits
        rjust(8, "0")
    end.
    # Join all the bits strings
    join.
    # Split the string into an array of characters (each is a bit)
    chars
end