binary 0.0.1 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -0
- data/lib/binary.rb +5 -3
- data/lib/binary/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7aea0a9e122f5815c78ee5d186eacc19162a08b6bcfd4e31aabe724fb646903
|
4
|
+
data.tar.gz: 4c9adaa9ee31905ebe31b39f6f08c3b6000698c2c9f379436fc56fcd6c015329
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be22f4282c26d008503775d1e9ea815ca48be732007fe804f7510262258271e2464274049a2f365029146cb289ab0320d7bb58e67d4a09b275c08ef5f64fb847
|
7
|
+
data.tar.gz: dd40123cc95e3a82d887549cf970f64018a115116dbef8705ed934fb4f471146f3ebe7efbaee8c5eee343a93be4e0c1b9ce8493987b3f0902b0c622e0056f627
|
data/README.md
CHANGED
@@ -32,6 +32,12 @@ Binary.binary(2018)
|
|
32
32
|
```
|
33
33
|
Output: `"11111100010"`.
|
34
34
|
|
35
|
+
Also you can pass an array of integers to the method to get an array of their binary values.
|
36
|
+
```ruby
|
37
|
+
Binary.binary([26,6,1991])
|
38
|
+
```
|
39
|
+
Output: `["11010", "110", "11111000111"]`.
|
40
|
+
|
35
41
|
## Development
|
36
42
|
|
37
43
|
...
|
data/lib/binary.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
require "binary/version"
|
2
2
|
|
3
3
|
module Binary
|
4
|
-
def self.binary(
|
5
|
-
|
6
|
-
|
4
|
+
def self.binary(input=nil)
|
5
|
+
if input.class == Array
|
6
|
+
input.map { |num| num.to_s(2) }
|
7
|
+
elsif input.class == Integer
|
8
|
+
input.to_s(2)
|
7
9
|
end
|
8
10
|
end
|
9
11
|
end
|
data/lib/binary/version.rb
CHANGED