Sha256: ec7e7e107ecfe02a4e6133eea8a2716cde87d418ce52e60f0af4650d0bb5b9fd

Contents?: true

Size: 825 Bytes

Versions: 54

Compression:

Stored size: 825 Bytes

Contents

# encoding: utf-8

# Numeric
class Numeric
  # return is hex table
  #
  # ==== Examples
  #
  # 65535 to 65536 case
  #
  #   Numeric.to_hex_html_table(65535, 65536)
  #
  # result
  #
  #   <table>
  #     <tr>
  #       <th>10digit</th>
  #       <th>16digit</th>
  #     </tr>
  #     <tr>
  #       <td>65535</td>
  #       <td>0000ffff</td>
  #     </tr>
  #     <tr>
  #       <td>65536</td>
  #       <td>00010000</td>
  #     </tr>
  #   </table>
  #
  def self.to_hex_html_table(from = 1, to = 10)
    ret = []
    size = to.to_s(16).size - 1
    pad = (size / 4 + 1) * 4
    ret << "<table>\n  <tr>\n    <th>10digit</th>\n    <th>16digit</th>\n  </tr>"
    (from..to).each { |i|ret << "  <tr>\n    <td>#{i}</td>\n    <td>#{i.to_s(16).rjust(pad, '0')}</td>\n  </tr>" }
    ret.join("\n") + "\n</table>\n"
  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

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