binToDec 0.0.5 → 0.0.6
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 +4 -4
- data/README.md +5 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 106d85904286c4c404981d6f06e6f5376c3d0641
|
4
|
+
data.tar.gz: f7c191e6015521bebba99092ab7210c92d70e5d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 231098ae0361ed08209e2ab76627acee97ef010b394bed52ce83716192fbdf68efb0533129947199bbbbd13c3ae29ee5cb2db177406c25c2195ccd7010b26390
|
7
|
+
data.tar.gz: 06cd1aa300f562b5c271ffe8879be04eef39dd7c39d53141711f2539c96181d669a7fc8359fba1ad110fbc714df73c343e242fad41a4aec08b8c38122f7d310b
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# Binary to Decimal Conversion (binToDec)
|
2
|
+
[](http://badge.fury.io/rb/binToDec)
|
2
3
|
|
3
|
-
binToDec is written in Ruby, and converts a binary number to a decimal only if
|
4
|
+
**binToDec** is written in Ruby, and converts a binary number to a decimal only if
|
4
5
|
the argument is binary.
|
5
6
|
|
6
7
|
It should be considered an experimental gem.
|
@@ -28,14 +29,14 @@ Converter.bintoDec(2)
|
|
28
29
|
## Basis
|
29
30
|
The program uses the following test to determine if the input is binary:
|
30
31
|
|
31
|
-
arg1.
|
32
|
+
`arg1.to_s.split(//).map { |i| i.to_i }.find_all { |value| value > 0 }.inject(:*)`
|
32
33
|
|
33
34
|
|
34
35
|
The program uses the following code to convert the input (arg1) to binary.
|
35
36
|
|
36
|
-
arg1.
|
37
|
+
`arg1.to_s.split(//).map { |i| i.to_i }.inject(0) { |accumulator, value| (accumulator + value) * 2 }`
|
37
38
|
|
38
|
-
|
39
|
+
`return result/2`
|
39
40
|
|
40
41
|
|
41
42
|
## Contributing
|