From c2d7d45995979d45e160659191218ad3192e8f1a Mon Sep 17 00:00:00 2001 From: analisasutherland Date: Mon, 26 Feb 2018 11:17:39 -0800 Subject: [PATCH] Create binary_to_decimal.rb --- binary_to_decimal.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 binary_to_decimal.rb diff --git a/binary_to_decimal.rb b/binary_to_decimal.rb new file mode 100644 index 0000000..7977cad --- /dev/null +++ b/binary_to_decimal.rb @@ -0,0 +1,14 @@ +# Write a method named binary_to_decimal that receives as input parameter an array of size 8. +nums = Array.new(8) +def binary_to_decimal (nums) + # The array is randomly filled with 0’s and 1’s + nums << rand(0..1) + # calculate the decimal value for this binary number using the + nums.each do |num| + decimal << num.to_s(10) + end + # return decimal + return decimal +end + +puts nums.binary_to_decimal