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

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • 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. PHP bindec function – Convert a number between arbitrary bases
  2. PHP function chop() – Alias of rtrim()
  3. PHP cos function – Cosine
  4. PHP function stripcslashes() – Un-quote string quoted with addcslashes()
  5. PHP function chunk_split() – Split a string into smaller chunks
  6. PHP atanh function – Inverse hyperbolic tangent
  7. PHP function abs – Absolute value
  8. PHP function chr() – Generate a single-byte string from a number
  9. PHP function str_replace() – Replace all occurrences of the search string with the replacement string
  10. PHP function str_ireplace() – Case-insensitive version of str_replace()

You May Also Like

Primary Sidebar

Recent Posts

  • Vanilla OS 2 Released: A New Era for Linux Enthusiasts
  • mk Command Examples
  • mixxx Command Examples
  • mix Command Examples

© 2025 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright