• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

PHP decbin function – Decimal to binary

by admin

The PHP function decbin() converts a decimal number into a string containing its binary representation. The largest decimal value that can be converted is 2147483647. If you have to deal with larger numbers, you need to write a custom function to handle the values. It takes just one parameter, which is the number to convert. For example:

print decbin(16); // "10000"

Syntax

decbin(int $num): string

Parameters

Parameter Description
num Decimal value to convert

Examples

Example 1: Get the binary representation of an integer.

$number = 42; 
echo "The binary of $number is ", decbin($number); 

Example 2:

echo decbin(12) . "\n";
echo decbin(26);

Output:

1100
11010

Filed Under: PHP

Some more articles you might also be interested in …

  1. “Access denied for user ‘username’@’hostname’ (using password: YES)” – Error while connecting MySQL with PHP
  2. PHP function acos – Arc cosine
  3. PHP atan2 function – Arc tangent of two variables
  4. How to test a PHP script
  5. PHP base_convert function – Convert a number between arbitrary bases
  6. PHP function str_replace() – Replace all occurrences of the search string with the replacement string
  7. PHP Function str_split() – Convert a string to an array
  8. PHP function convert_cyr_string() – Convert from one Cyrillic character set to another
  9. htaccess Cheatsheet
  10. PHP Function strncasecmp() – Binary safe case-insensitive string comparison of the first n characters

You May Also Like

Primary Sidebar

Recent Posts

  • nixos-rebuild Command Examples in Linux
  • nixos-option: Command Examples in Linux
  • nixos-container : Command Examples in Linux
  • nitrogen Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright