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

  • SEARCH
  • Home
  • 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 4023094
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:33:24+00:00 2026-05-20T10:33:24+00:00

For example, I need to grab an unknown number, let’s say 3, and find

  • 0

For example, I need to grab an unknown number, let’s say 3, and find the binary (2^3) – 1 times, from 0 to 111 (0-7). Obviously, the number of digits I need depends on whatever number ‘n’ in 2^n.

So, if the number is 3, I would need the output to be:

000
001
010
011
100
101
111

Now obviously I can do this manually with a String.format(“%03d”, NumberInBinary) operation, but that’s hardcoding it for 3 digits. I need to do the equivalent code with an unknown number of digits, how can I do that? (as in String.format(“%0nd”, yournumber) where n is the number of digits.)

  • 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-05-20T10:33:25+00:00Added an answer on May 20, 2026 at 10:33 am

    if n = 4, NumberInBinary = 101;

    String.format("%0"+n+"d", NumberInBinary);
    

    with output

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

Sidebar

Related Questions

For example I need to grab from http://gmail.com/ the number of free storage: Over
There is an online file (such as http://www.example.com/information.asp ) I need to grab and
A specific example I need to generate a random number between 0 and 2,
I need an example of the shortest path of a directed cyclic graph from
I need to grab the statuses from a Facebook page via PHP to display
I need to grab the base64-encoded representation of the ViewState . Obviously, this would
I need grab the path of a referring URL, which can be served from
I need to grab the height of a tableView cell from within the tableView:cellForRowAtIndexPath
For Example: I need to develop a Small Inventory program for nearby Super Market
For example I need to disable two buttons in runtime. After I disabled first

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.