programming-examples/ruby/Algorithms/add_binary.rb

9 lines
188 B
Ruby
Raw Normal View History

2019-11-15 12:59:38 +01:00
# Given two binary strings, return their sum (also a binary string).
# @param {String} a
# @param {String} b
# @return {String}
def add_binary(a, b)
(a.to_i(2) + b.to_i(2)).to_s(2)
end