Dec2Hex 1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/dectohex.rb +47 -0
- metadata +43 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7b4d0297d73ad3498d93538f84c096d5de04331935f275f678a949e065650376
|
4
|
+
data.tar.gz: a9a579b1b7e8bf7021340ef7139e888b69586fafefe38d30fa695fc9a81e3eed
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ff53a36d6d21de4b62443a5d4f9161b335d8266ebb079da96deb7cb633157bf7c1dfcc3d7e8983e222d3ad5cc7d1a198addcb50aa6305810c6e6bbfbb62417ec
|
7
|
+
data.tar.gz: 5c9864e4e5ba05de03718a600c210b0c2584675158cf50fcb8d4d7b7bd57fb801cd573c76834bedad610c1f4cd9c691c6f047cc617ca69d36bd0cddf9573da5b
|
data/lib/dectohex.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
class TypeError < StandardError
|
2
|
+
end
|
3
|
+
|
4
|
+
class Arg < ArgumentError
|
5
|
+
end
|
6
|
+
|
7
|
+
|
8
|
+
def dec2hex(decimal_number)
|
9
|
+
|
10
|
+
if decimal_number == nil
|
11
|
+
raise Arg, "Argument decimal number is empty (example: dec2hex(1337))"
|
12
|
+
end
|
13
|
+
|
14
|
+
if decimal_number.class != Integer
|
15
|
+
raise TypeError, "Incorrect class object Integer"
|
16
|
+
end
|
17
|
+
|
18
|
+
hexa_result = Array.new
|
19
|
+
tmp_result = decimal_number
|
20
|
+
used = true
|
21
|
+
hash_letters = { 10 => "A", 11 => "B", 12 => "C", 13 => "D", 14 => "E", 15 => "F" }
|
22
|
+
final_result = []
|
23
|
+
while true
|
24
|
+
|
25
|
+
while(tmp_result / 16 != tmp_result % 16)
|
26
|
+
if(used == true)
|
27
|
+
tmp_result = decimal_number / 16
|
28
|
+
hexa_result << decimal_number % 16
|
29
|
+
used = false
|
30
|
+
end
|
31
|
+
hexa_result << tmp_result % 16
|
32
|
+
tmp_result = tmp_result / 16
|
33
|
+
end
|
34
|
+
break
|
35
|
+
end
|
36
|
+
|
37
|
+
hexa_result.each do |fixnum|
|
38
|
+
if(hash_letters.has_key?(fixnum) == true)
|
39
|
+
final_result << hash_letters[fixnum]
|
40
|
+
else
|
41
|
+
final_result << fixnum
|
42
|
+
end
|
43
|
+
end
|
44
|
+
return final_result.reverse.join
|
45
|
+
end
|
46
|
+
|
47
|
+
puts dec2hex(516556516561516561561561566556556566)
|
metadata
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: Dec2Hex
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Muham'RB
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-05-30 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Method to convert decimal to hexadecimal
|
14
|
+
email: paraghostsociety@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/dectohex.rb
|
20
|
+
homepage: https://rubygems.org/gems/dec2hex
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubygems_version: 3.1.2
|
40
|
+
signing_key:
|
41
|
+
specification_version: 4
|
42
|
+
summary: Method to convert decimal to hexadecimal
|
43
|
+
test_files: []
|