binary 1.1.0 → 1.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 +27 -5
- 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: 75468b4cae9ef1a47cc46ca0eb99c9fb85add39974ef077578dd40b413afa80d
|
4
|
+
data.tar.gz: d1aea9ccf064910c3ebf4e8176ae199d2aa3df781c562e572de15034859cc7b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9df1158b6adc4b43fbde0705077cfa02813c4d7c844b4357e6ef641d114ae41a23d48319c4fe300c49ba154f9059f3f1448a46ada83b52dea34f52e43d1c0dc
|
7
|
+
data.tar.gz: 4091347bfafee9191823590b5a5ce9f2697c2217d1ea46039d7e7f97b84dc45c505d2342688f4e68a743bbd20fb66721dfc248221e5481b078897c31a0a59db9
|
data/README.md
CHANGED
@@ -28,19 +28,41 @@ require 'binary'
|
|
28
28
|
Then to get the binary representation of a number, you just need to call `Binary.binary` and pass the number to it, something like follows:
|
29
29
|
|
30
30
|
```ruby
|
31
|
-
Binary.binary
|
31
|
+
Binary.binary 2018
|
32
32
|
```
|
33
|
-
Output:
|
33
|
+
`Output: "11111100010"`.
|
34
34
|
|
35
35
|
Also you can pass an array of integers to the method to get an array of their binary values.
|
36
36
|
```ruby
|
37
37
|
Binary.binary([26,6,1991])
|
38
38
|
```
|
39
|
-
Output:
|
39
|
+
`Output: ["11010", "110", "11111000111"]`.
|
40
40
|
|
41
|
-
|
41
|
+
Other methods you can use:
|
42
42
|
|
43
|
-
|
43
|
+
```ruby
|
44
|
+
# number of bits in a number's binary
|
45
|
+
Binary.bits 1000
|
46
|
+
```
|
47
|
+
`Output: 10`.
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
# number of ones in a number's binary
|
51
|
+
Binary.ones 1000
|
52
|
+
```
|
53
|
+
`Output: 6`.
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
# number of zeros in a number's binary
|
57
|
+
Binary.zeros 1000
|
58
|
+
```
|
59
|
+
`Output: 4`.
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
# get array of binaries of all prime numbers between 2 and the given number
|
63
|
+
Binary.prime 25
|
64
|
+
```
|
65
|
+
`Output: ["10", "11", "101", "111", "1011", "1101", "10001", "10011", "10111"]`.
|
44
66
|
|
45
67
|
## Contributing
|
46
68
|
|
data/lib/binary/version.rb
CHANGED