Sha256: f5469845ad5e26e0768c9267ab41c00c94e1fb5b84684674f8bac89e00ee7cfb

Contents?: true

Size: 603 Bytes

Versions: 72

Compression:

Stored size: 603 Bytes

Contents

# encoding: utf-8

# Numeric
class Numeric
  # return is binary table
  #
  # ==== Examples
  #
  # 1 to 3 case
  #
  #   Numeric.to_binary_table(1, 3)
  #
  # result
  #
  #   |10digit|2digit  |
  #   |1      |00000001|
  #   |2      |00000010|
  #   |3      |00000011|
  #
  def self.to_binary_table(from = 1, to = 10)
    ret = []
    size = to.to_s(2).size - 1
    pad = (size / 8 + 1) * 8
    ret << '|10digit|2digit|'
    (from..to).each { |i|ret << "|#{i}|#{i.to_s(2).rjust(pad, '0')}|" }
    joined = ret.join("\n") + "\n"
    joined.justify_table(:right)
  end
end

Version data entries

72 entries across 72 versions & 1 rubygems

Version Path
tbpgr_utils-0.0.151 lib/open_classes/numeric/to_binary_table.rb
tbpgr_utils-0.0.150 lib/open_classes/numeric/to_binary_table.rb
tbpgr_utils-0.0.149 lib/open_classes/numeric/to_binary_table.rb
tbpgr_utils-0.0.148 lib/open_classes/numeric/to_binary_table.rb
tbpgr_utils-0.0.147 lib/open_classes/numeric/to_binary_table.rb
tbpgr_utils-0.0.146 lib/open_classes/numeric/to_binary_table.rb
tbpgr_utils-0.0.145 lib/open_classes/numeric/to_binary_table.rb
tbpgr_utils-0.0.144 lib/open_classes/numeric/to_binary_table.rb
tbpgr_utils-0.0.143 lib/open_classes/numeric/to_binary_table.rb
tbpgr_utils-0.0.142 lib/open_classes/numeric/to_binary_table.rb
tbpgr_utils-0.0.141 lib/open_classes/numeric/to_binary_table.rb
tbpgr_utils-0.0.140 lib/open_classes/numeric/to_binary_table.rb
tbpgr_utils-0.0.139 lib/open_classes/numeric/to_binary_table.rb
tbpgr_utils-0.0.138 lib/open_classes/numeric/to_binary_table.rb
tbpgr_utils-0.0.137 lib/open_classes/numeric/to_binary_table.rb
tbpgr_utils-0.0.136 lib/open_classes/numeric/to_binary_table.rb
tbpgr_utils-0.0.135 lib/open_classes/numeric/to_binary_table.rb
tbpgr_utils-0.0.134 lib/open_classes/numeric/to_binary_table.rb
tbpgr_utils-0.0.133 lib/open_classes/numeric/to_binary_table.rb
tbpgr_utils-0.0.132 lib/open_classes/numeric/to_binary_table.rb