• 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. PHP function chop() – Alias of rtrim()
  2. PHP Function str_word_count() – Return information about words used in a string
  3. PHP atan2 function – Arc tangent of two variables
  4. PHP Function strchr() – Alias of strstr()
  5. PHP function stripcslashes() – Un-quote string quoted with addcslashes()
  6. PHP function stripslashes() – Un-quotes a quoted string
  7. PHP function acos – Arc cosine
  8. PHP function strlen() – Get string length
  9. PHP function str_repeat() – Repeat a string
  10. PHP bindec function – Convert a number between arbitrary bases

You May Also Like

Primary Sidebar

Recent Posts

  • ctags: Generates an index (or tag) file of language objects found in source files for many popular programming languages
  • csvtool: Utility to filter and extract data from CSV formatted sources
  • csvstat: Print descriptive statistics for all columns in a CSV file
  • csvsql: Generate SQL statements for a CSV file or execute those statements directly on a database

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright