Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Execute Ruby Online

class Binar
    def binar
        print "Input number to convert: "
        number = gets.to_i
        numerical_system = nil

        until(1..3).include?(numerical_system)      
            print "Select numeric system to convert: 1.Binar 2.Octal 3.Hexadecimal"
            numerical_system = gets.chomp
        end
        
        if numerical_system == 1
            y = number.to_s(2)
            s = "Binar"
        elsif numerical_system == 2
            y = number.to_s(8)
            s = "Octal"
        else
            y = number.to_s(16)
            s = "Hexadecimal"
        end
        
        print "#{number} in #{s} numerical system is #{y}"
    end
end

convert = Binar.new
convert.binar

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.