# encoding: utf-8 # Numeric class Numeric # return is digit html table # # ==== Examples # # 255 to 256 case # # Numeric.to_digit_html_table(255, 256) # # result # # # # # # # # # # # # # # # # # # # # #
10digit2digit8digit16digit
255000000001111111137700ff
25600000001000000004000100
# def self.to_digit_html_table(from = 1, to = 10) ret = [] binary_size = to.to_s(2).size - 1 binary_pad = (binary_size / 8 + 1) * 8 oct_size = to.to_s(8).size hex_size = to.to_s(16).size - 1 hex_pad = (hex_size / 4 + 1) * 4 ret << "\n \n \n \n \n \n " (from..to).each { |i|ret << " \n \n \n \n \n " } ret.join("\n") + "\n
10digit2digit8digit16digit
#{i}#{i.to_s(2).rjust(binary_pad, '0')}#{i.to_s(8).rjust(oct_size, '0')}#{i.to_s(16).rjust(hex_pad, '0')}
\n" end end