PHP | decbin( ) Function

While working with numbers, many times we need to convert the bases of number and one of the most frequent used conversion is decimal to binary conversion. PHP provides us with a built-in function, decbin() for this purpose.The decbin() function in PHP is used to return a string containing a binary representation of the given decimal number argument.
decbin stands for decimal to binary.

Syntax:

string decbin(value)

Parameters: This function accepts a single parameter value. It is the decimal number which you want to convert in binary representation.



Return Value: It returns a string that represent the binary value of the decimal number passed to the function as argument.

Examples:

Input : decbin(12)
Output : 1100

Input : decbin(26)
Output : 11010

Input : decbin(2147483647)
Output : 1111111111111111111111111111111 (31 1's)

Below programs illustrate the decbin() function in PHP:

  • Passing 12 as a parameter
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <?php
      
    echo decbin(12);
      
    ?>    

    chevron_right

    
    

    Output:

    1100
  • Passing 26 as a parameter:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <?php
      
    echo decbin(26);
      
    ?>   

    chevron_right

    
    

    Output:

    11010
  • When the largest signed integer is passed as a parameter:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <?php
      
    echo decbin(2147483647);
      
    ?>      

    chevron_right

    
    

    Output:

     1111111111111111111111111111111  

Reference:
http://php.net/manual/en/function.decbin.php



My Personal Notes arrow_drop_up

I am a technology enthusiast who has a keen interest in programming I am pursuing Engineering in Computer Science from GEU, Dehradun I like to unwind by watching movies and English sitcomsI have a keen interest in music

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.