Problem with printf () function

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


here is the script

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

it does not work with *, but if "0" -s works

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

why doesn't it work with *?

EDIT:

and how can i apply a floating parameter? as

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

    //it returns 5.0000, but i want to return *****101.0000
+3
source share
1 answer

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

, , . 0 ( ). - . ('). . .

,

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

EDIT:

try

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

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

+3

Source: https://habr.com/ru/post/1737964/


All Articles