class Numeric

Numeric

Numeric

Numeric

Numeric

Numeric

Numeric

Numeric

Numeric

Numeric

Numeric

Numeric

Constants

DICE

dice number mappings

Public Class Methods

to_binary_html_table(from = 1, to = 10) click to toggle source

binary table

Examples

1 to 3 case

Numeric.to_binary_html_table(1, 3)

result

<table>
  <tr>
    <th>10digit</th>
    <th>2digit</th>
  </tr>
  <tr>
    <td>255</td>
    <td>0000000011111111</td>
  </tr>
  <tr>
    <td>256</td>
    <td>0000000100000000</td>
  </tr>
</table>
# File lib/open_classes/numeric/to_binary_html_table.rb, line 30
def self.to_binary_html_table(from = 1, to = 10)
  ret = []
  size = to.to_s(2).size - 1
  pad = (size / 8 + 1) * 8
  ret << "<table>\n  <tr>\n    <th>10digit</th>\n    <th>2digit</th>\n  </tr>"

  (from..to).each { |i|ret << "  <tr>\n    <td>#{i}</td>\n    <td>#{i.to_s(2).rjust(pad, '0')}</td>\n  </tr>" }
  ret.join("\n") + "\n</table>\n"
end
to_binary_table(from = 1, to = 10) click to toggle source

return is binary table

Examples

1 to 3 case

Numeric.to_binary_table(1, 3)

result

|10digit|2digit  |
|1      |00000001|
|2      |00000010|
|3      |00000011|
# File lib/open_classes/numeric/to_binary_table.rb, line 20
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
to_digit_html_table(from = 1, to = 10) click to toggle source

return is digit html table

Examples

255 to 256 case

Numeric.to_digit_html_table(255, 256)

result

<table>
  <tr>
    <th>10digit</th>
    <th>2digit</th>
    <th>8digit</th>
    <th>16digit</th>
  </tr>
  <tr>
    <td>255</td>
    <td>0000000011111111</td>
    <td>377</td>
    <td>00ff</td>
  </tr>
  <tr>
    <td>256</td>
    <td>0000000100000000</td>
    <td>400</td>
    <td>0100</td>
  </tr>
</table>
# File lib/open_classes/numeric/to_digit_html_table.rb, line 36
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 << "<table>\n  <tr>\n    <th>10digit</th>\n    <th>2digit</th>\n    <th>8digit</th>\n    <th>16digit</th>\n  </tr>"
  (from..to).each { |i|ret << "  <tr>\n    <td>#{i}</td>\n    <td>#{i.to_s(2).rjust(binary_pad, '0')}</td>\n    <td>#{i.to_s(8).rjust(oct_size, '0')}</td>\n    <td>#{i.to_s(16).rjust(hex_pad, '0')}</td>\n  </tr>" }
  ret.join("\n") + "\n</table>\n"
end
to_digit_table(from = 1, to = 10) click to toggle source

return is digit table

Examples

255 to 256 case

Numeric.to_digit_table(255, 256)

result

|10digit|          2digit|8digit|16digit|
|    255|0000000011111111|   377|   00ff|
|    256|0000000100000000|   400|   0100|
# File lib/open_classes/numeric/to_digit_table.rb, line 19
def self.to_digit_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 << '|10digit|2digit|8digit|16digit|'
  (from..to).each { |i|ret << "|#{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')}|" }
  joined = ret.join("\n") + "\n"
  joined.justify_table(:right)
end
to_hex_html_table(from = 1, to = 10) click to toggle source

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>
# File lib/open_classes/numeric/to_hex_html_table.rb, line 30
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
to_hex_table(from = 1, to = 10) click to toggle source

return is hex table

Examples

65535 to 65536 case

Numeric.to_hex_table(65535, 65536)

result

|10digit| 16digit|
|  65535|0000ffff|
|  65536|00010000|
# File lib/open_classes/numeric/to_hex_table.rb, line 19
def self.to_hex_table(from = 1, to = 10)
  ret = []
  size = to.to_s(16).size - 1
  pad = (size / 4 + 1) * 4
  ret << '|10digit|16digit|'
  (from..to).each { |i|ret << "|#{i}|#{i.to_s(16).rjust(pad, '0')}|" }
  joined = ret.join("\n") + "\n"
  joined.justify_table(:right)
end
to_oct_html_table(from = 1, to = 10) click to toggle source

return is oct html table

Examples

65535 to 65536 case

Numeric.to_oct_html_table(65535, 65536)

result

<table>
  <tr>
    <th>10digit</th>
    <th>8digit</th>
  </tr>
  <tr>
    <td>65535</td>
    <td>177777</td>
  </tr>
  <tr>
    <td>65536</td>
    <td>200000</td>
  </tr>
</table>
# File lib/open_classes/numeric/to_oct_html_table.rb, line 30
def self.to_oct_html_table(from = 1, to = 10)
  ret = []
  size = to.to_s(8).size
  ret << "<table>\n  <tr>\n    <th>10digit</th>\n    <th>8digit</th>\n  </tr>"
  (from..to).each { |i|ret << "  <tr>\n    <td>#{i}</td>\n    <td>#{i.to_s(8)}</td>\n  </tr>" }
  ret.join("\n") + "\n</table>\n"
end
to_oct_table(from = 1, to = 10) click to toggle source

return is oct table

Examples

65535 to 65536 case

Numeric.to_oct_table(65535, 65536)

result

|10digit|8digit|
|  65535|177777|
|  65536|200000|
# File lib/open_classes/numeric/to_oct_table.rb, line 19
def self.to_oct_table(from = 1, to = 10)
  ret = []
  size = to.to_s(8).size
  ret << '|10digit|8digit|'
  (from..to).each { |i|ret << "|#{i}|#{i.to_s(8).rjust(size, '0')}|" }
  joined = ret.join("\n") + "\n"
  joined.justify_table(:right)
end

Public Instance Methods

ascii?() click to toggle source

return is ascii or not

Examples

1,127,128 case

1.ascii? # => return true
127.ascii? # => return true
128.ascii? # => return false
# File lib/open_classes/numeric/is_ascii.rb, line 15
def ascii?
  self < 128
end
dice_back() click to toggle source

return dice back number

Examples

each 1-6 case

1.dice_back # => return 6
2.dice_back # => return 5
3.dice_back # => return 4
4.dice_back # => return 3
5.dice_back # => return 2
6.dice_back # => return 1

other case

7.dice_back # => return 7
# File lib/open_classes/numeric/dice_back.rb, line 25
def dice_back
  DICE.include?(self) ? DICE[self] : self
end
dozen() click to toggle source

get dozen number

Examples

0,1,2 case

0.dozen # => return 0
1.dozen # => return 12
2.dozen # => return 24
# File lib/open_classes/numeric/dozen.rb, line 15
def dozen
  return 0 if self == 0
  self * 12
end