Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8510969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:51:23+00:00 2026-06-11T03:51:23+00:00

I am trying to convert a variable, which will always be a number, into

  • 0

I am trying to convert a variable, which will always be a number, into binary, octal, and hex with Ruby.

The code I have at this point is:

def convert(number)
  puts "#{number} in decimal is"
  puts "#{number.to_s(2)} in binary"
  puts "#{number.to_s(8)} in octal"
  puts "#{number.to_s(16)} in hexadecimal"
end

and so far the output is:

2 in decimal is
10 in binary
2 in octal
2 in hexadecimal

The first two lines run fine, but after that it is ignoring the conversion command and just putting the variable in. Does anyone have any idea what it is I am missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T03:51:25+00:00Added an answer on June 11, 2026 at 3:51 am

    You are missing the fact that 2 is… 2 in base 8, 16, or any base greater than 2. Try convert(42) for fun.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to convert this c code into MIPS and run it in SPIM. int
Trying to convert a string of binary inputs into a vector of ints. I'd
im trying to convert a date format into a new format in this example
I'm trying to convert this Javascript code: self.userSerialEvent = function (join, value, tokens) {
I'm trying to find all text files which have the encoding iso-8859-1 and convert
Trying to convert some VB to C#... (learning C#, too). I have some code
I'm trying to convert a variable named $releasedate which contains the string 'May 31,
I'm trying convert all special chars into HTML safe entities on their way into
I have the following script for importing text files into matlab which include hourly
I'm trying to convert a Netbeans 6.9.1 project into a scripted build (without netbeans).

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.