binToDec 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/binToDec.rb +14 -0
- metadata +43 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0a34672d4c0e126adb43eb4324ccbb934aff75dd
|
4
|
+
data.tar.gz: 2f2ce32ab26efefd746e24a223ebe6e319151f63
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c2a28cf3c83ecb9c63c38c01541b5a3b72b0d0e511dc813343bccadae82a4cf81d447b32f5689a8f0f3c5b2c39f788560d180cc0e1183ffb7135903f6f9f9250
|
7
|
+
data.tar.gz: 36af391fe6c697abbd78d4849c61b1fa348e8a05b2ebcfacc183e3b838c36bf506dd03c517495d7628bd23368fc78685ce7fbeb4be8d5109b5c7c345ea1ca182
|
data/lib/binToDec.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
module Converter
|
2
|
+
def self.binToDec(arg1)
|
3
|
+
#TEST FOR BINARY INPUT: my_test_file will be equal to 1 only if binary number is input
|
4
|
+
my_test = arg1.to_s.split(//).map { |i| i.to_i }.find_all { |value| value > 0 }.inject(:*)
|
5
|
+
if my_test ==1
|
6
|
+
# Generate a binary number using the "move to the right and double" method
|
7
|
+
result = arg1.to_s.split(//).map { |i| i.to_i }.inject(0) { |accumulator, value| (accumulator + value) * 2 }
|
8
|
+
#The above result will be double what it should be, so need to divide by 2
|
9
|
+
return result/2
|
10
|
+
else
|
11
|
+
print "!Not a binary number: #{arg1}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: binToDec
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- tomgdow
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-11 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A simple gem
|
14
|
+
email: thomasgdowling@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/binToDec.rb
|
20
|
+
homepage: http://rubygems.org/gems/binToDec
|
21
|
+
licenses: []
|
22
|
+
metadata: {}
|
23
|
+
post_install_message:
|
24
|
+
rdoc_options: []
|
25
|
+
require_paths:
|
26
|
+
- lib
|
27
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ! '>='
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: '0'
|
32
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ! '>='
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
requirements: []
|
38
|
+
rubyforge_project:
|
39
|
+
rubygems_version: 2.1.5
|
40
|
+
signing_key:
|
41
|
+
specification_version: 4
|
42
|
+
summary: Convert a Binary Number to Decimal
|
43
|
+
test_files: []
|