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 681383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:28:39+00:00 2026-05-14T01:28:39+00:00

i have the variable $a = 5; i want to show it in binary

  • 0

i have the variable $a = 5; i want to show it in binary form, with length, equal 8, with writing * at white spaces, just like this, like this * * * * *101


here the script

$number = 5;
printf("%*8b", $number); 

it doesn’t work with *, but if “0”-s it works

   printf("%08b", $number);
      //returns 00000101

why it doesn’t work with *?

EDIT:

and how can i apply the floating option too? like

`printf("%.4f", $number);` 

    //it returns 5.0000, but i want to return *****101.0000
  • 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-14T01:28:39+00:00Added an answer on May 14, 2026 at 1:28 am

    http://www.php.net/manual/en/function.sprintf.php

    An optional padding specifier that
    says what character will be used for
    padding the results to the right
    string size. This may be a space
    character or a 0 (zero character). The
    default is to pad with spaces. An
    alternate padding character can be
    specified by prefixing it with a
    single quote (‘). See the examples
    below.

    So, use

    printf("%'*8b", $number); 
    

    EDIT:

    for float try

    printf("%'*.4f", $number); 
    

    and if you want some more complicated cases, just read http://www.php.net/manual/en/function.sprintf.php

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

Sidebar

Related Questions

I have a ListBox which displays items of variable height. I want to show
I have a long snippet of HTML I want some javascript variable to equal
I have a variable last_login and want to output a message if the last
I have a date variable as 24-dec-08 . I want only the 08 component
In Java, suppose I have a String variable S, and I want to search
If I have a std::vector or std::map variable, and I want to see the
I have a variable that is built in loop. Something like: $str = ;
How do I manipulate textfield variables within an iPhone app? I want to have
If I have variable of type IEnumerable<List<string>> is there a LINQ statement or lambda
I have a variable of type Dynamic and I know for sure one of

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.