{"id":41,"date":"2026-03-26T08:00:33","date_gmt":"2026-03-26T08:00:33","guid":{"rendered":"https:\/\/medium.com\/p\/b15bb163c780"},"modified":"2026-03-25T09:59:39","modified_gmt":"2026-03-25T09:59:39","slug":"how-to-print-binary-representation-of-an-integer-in-php","status":"publish","type":"post","link":"https:\/\/kishor10d.com\/blogs\/how-to-print-binary-representation-of-an-integer-in-php\/","title":{"rendered":"How to Print Binary Representation of an Integer in PHP"},"content":{"rendered":"<p>In PHP, printing the binary representation of an integer is very simple.<\/p>\n<p>We will learn how to print binary representation of an integer in PHP using some example given below.<\/p>\n<hr \/>\n<h2>1. Using built-in function <code>decbin()<\/code><\/h2>\n<pre><code class=\"language-php\">$number = 10;\r\necho decbin($number);\r\n<\/code><\/pre>\n<p><strong>Output:<\/strong><\/p>\n<pre><code>1010\r\n<\/code><\/pre>\n<p>This is the easiest and most common way.<\/p>\n<hr \/>\n<h2>2. With leading zeros (fixed length)<\/h2>\n<p>If you want a fixed number of bits (e.g., 8-bit):<\/p>\n<pre><code class=\"language-php\">$number = 10;\r\necho str_pad(decbin($number), 8, \"0\", STR_PAD_LEFT);\r\n<\/code><\/pre>\n<p><strong>Output:<\/strong><\/p>\n<pre><code>00001010\r\n<\/code><\/pre>\n<hr \/>\n<h2>3. Manual method (for understanding)<\/h2>\n<pre><code class=\"language-php\">$number = 10;\r\n$binary = \"\";\r\n\r\nwhile ($number &gt; 0) {\r\n    $binary = ($number % 2) . $binary;\r\n    $number = intdiv($number, 2);\r\n}\r\n\r\necho $binary;\r\n<\/code><\/pre>\n<hr \/>\n<h2>Tip<\/h2>\n<ul>\n<li><code>decbin()<\/code> works only for <strong>decimal \u2192 binary<\/strong><\/li>\n<li>For reverse, use <code>bindec()<\/code><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>In PHP, printing the binary representation of an integer is very simple. We will learn how to print binary representation of an integer in PHP&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[5,17],"tags":[132,129,43,128,131,130,134,133],"class_list":["post-41","post","type-post","status-publish","format-standard","hentry","category-php","category-programming","tag-binary-representation","tag-decbin-php","tag-php","tag-php-binary-conversion","tag-php-functions","tag-php-programming","tag-php-tips","tag-web-development"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Print Binary Representation of an Integer in PHP<\/title>\n<meta name=\"description\" content=\"Learn how to print the binary representation of an integer in PHP using built-in functions like decbin() and simple methods. Easy examples for beginners and developers.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/kishor10d.com\/blogs\/how-to-print-binary-representation-of-an-integer-in-php\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Print Binary Representation of an Integer in PHP\" \/>\n<meta property=\"og:description\" content=\"Learn how to print the binary representation of an integer in PHP using built-in functions like decbin() and simple methods. Easy examples for beginners and developers.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/kishor10d.com\/blogs\/how-to-print-binary-representation-of-an-integer-in-php\/\" \/>\n<meta property=\"og:site_name\" content=\"Practical Kishor\" \/>\n<meta property=\"article:published_time\" content=\"2026-03-26T08:00:33+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/kishor10d.com\/blogs\/how-to-print-binary-representation-of-an-integer-in-php\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/kishor10d.com\/blogs\/how-to-print-binary-representation-of-an-integer-in-php\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\/\/kishor10d.com\/blogs\/#\/schema\/person\/682d05c56912dd235403d4d49862750a\"},\"headline\":\"How to Print Binary Representation of an Integer in PHP\",\"datePublished\":\"2026-03-26T08:00:33+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/kishor10d.com\/blogs\/how-to-print-binary-representation-of-an-integer-in-php\/\"},\"wordCount\":82,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/kishor10d.com\/blogs\/#\/schema\/person\/682d05c56912dd235403d4d49862750a\"},\"keywords\":[\"binary representation\",\"decbin PHP\",\"php\",\"PHP binary conversion\",\"PHP functions\",\"PHP programming\",\"PHP tips\",\"web development\"],\"articleSection\":[\"PHP\",\"Programming\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/kishor10d.com\/blogs\/how-to-print-binary-representation-of-an-integer-in-php\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/kishor10d.com\/blogs\/how-to-print-binary-representation-of-an-integer-in-php\/\",\"url\":\"https:\/\/kishor10d.com\/blogs\/how-to-print-binary-representation-of-an-integer-in-php\/\",\"name\":\"How to Print Binary Representation of an Integer in PHP\",\"isPartOf\":{\"@id\":\"https:\/\/kishor10d.com\/blogs\/#website\"},\"datePublished\":\"2026-03-26T08:00:33+00:00\",\"description\":\"Learn how to print the binary representation of an integer in PHP using built-in functions like decbin() and simple methods. Easy examples for beginners and developers.\",\"breadcrumb\":{\"@id\":\"https:\/\/kishor10d.com\/blogs\/how-to-print-binary-representation-of-an-integer-in-php\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/kishor10d.com\/blogs\/how-to-print-binary-representation-of-an-integer-in-php\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/kishor10d.com\/blogs\/how-to-print-binary-representation-of-an-integer-in-php\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/kishor10d.com\/blogs\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Print Binary Representation of an Integer in PHP\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/kishor10d.com\/blogs\/#website\",\"url\":\"https:\/\/kishor10d.com\/blogs\/\",\"name\":\"Practical Kishor\",\"description\":\"The quick brown fox jumps over the lazy dog\",\"publisher\":{\"@id\":\"https:\/\/kishor10d.com\/blogs\/#\/schema\/person\/682d05c56912dd235403d4d49862750a\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/kishor10d.com\/blogs\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/kishor10d.com\/blogs\/#\/schema\/person\/682d05c56912dd235403d4d49862750a\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/56b0564d13413fec0713653cf76e91ba4d9c5fbbf6dbe0a8adbd3941c88bc1e4?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/56b0564d13413fec0713653cf76e91ba4d9c5fbbf6dbe0a8adbd3941c88bc1e4?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/56b0564d13413fec0713653cf76e91ba4d9c5fbbf6dbe0a8adbd3941c88bc1e4?s=96&d=mm&r=g\",\"caption\":\"admin\"},\"logo\":{\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/56b0564d13413fec0713653cf76e91ba4d9c5fbbf6dbe0a8adbd3941c88bc1e4?s=96&d=mm&r=g\"},\"sameAs\":[\"https:\/\/kishor10d.com\/blogs\"],\"url\":\"https:\/\/kishor10d.com\/blogs\/author\/kishor10d\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Print Binary Representation of an Integer in PHP","description":"Learn how to print the binary representation of an integer in PHP using built-in functions like decbin() and simple methods. Easy examples for beginners and developers.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/kishor10d.com\/blogs\/how-to-print-binary-representation-of-an-integer-in-php\/","og_locale":"en_US","og_type":"article","og_title":"How to Print Binary Representation of an Integer in PHP","og_description":"Learn how to print the binary representation of an integer in PHP using built-in functions like decbin() and simple methods. Easy examples for beginners and developers.","og_url":"https:\/\/kishor10d.com\/blogs\/how-to-print-binary-representation-of-an-integer-in-php\/","og_site_name":"Practical Kishor","article_published_time":"2026-03-26T08:00:33+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/kishor10d.com\/blogs\/how-to-print-binary-representation-of-an-integer-in-php\/#article","isPartOf":{"@id":"https:\/\/kishor10d.com\/blogs\/how-to-print-binary-representation-of-an-integer-in-php\/"},"author":{"name":"admin","@id":"https:\/\/kishor10d.com\/blogs\/#\/schema\/person\/682d05c56912dd235403d4d49862750a"},"headline":"How to Print Binary Representation of an Integer in PHP","datePublished":"2026-03-26T08:00:33+00:00","mainEntityOfPage":{"@id":"https:\/\/kishor10d.com\/blogs\/how-to-print-binary-representation-of-an-integer-in-php\/"},"wordCount":82,"commentCount":0,"publisher":{"@id":"https:\/\/kishor10d.com\/blogs\/#\/schema\/person\/682d05c56912dd235403d4d49862750a"},"keywords":["binary representation","decbin PHP","php","PHP binary conversion","PHP functions","PHP programming","PHP tips","web development"],"articleSection":["PHP","Programming"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/kishor10d.com\/blogs\/how-to-print-binary-representation-of-an-integer-in-php\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/kishor10d.com\/blogs\/how-to-print-binary-representation-of-an-integer-in-php\/","url":"https:\/\/kishor10d.com\/blogs\/how-to-print-binary-representation-of-an-integer-in-php\/","name":"How to Print Binary Representation of an Integer in PHP","isPartOf":{"@id":"https:\/\/kishor10d.com\/blogs\/#website"},"datePublished":"2026-03-26T08:00:33+00:00","description":"Learn how to print the binary representation of an integer in PHP using built-in functions like decbin() and simple methods. Easy examples for beginners and developers.","breadcrumb":{"@id":"https:\/\/kishor10d.com\/blogs\/how-to-print-binary-representation-of-an-integer-in-php\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/kishor10d.com\/blogs\/how-to-print-binary-representation-of-an-integer-in-php\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/kishor10d.com\/blogs\/how-to-print-binary-representation-of-an-integer-in-php\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/kishor10d.com\/blogs\/"},{"@type":"ListItem","position":2,"name":"How to Print Binary Representation of an Integer in PHP"}]},{"@type":"WebSite","@id":"https:\/\/kishor10d.com\/blogs\/#website","url":"https:\/\/kishor10d.com\/blogs\/","name":"Practical Kishor","description":"The quick brown fox jumps over the lazy dog","publisher":{"@id":"https:\/\/kishor10d.com\/blogs\/#\/schema\/person\/682d05c56912dd235403d4d49862750a"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/kishor10d.com\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/kishor10d.com\/blogs\/#\/schema\/person\/682d05c56912dd235403d4d49862750a","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/56b0564d13413fec0713653cf76e91ba4d9c5fbbf6dbe0a8adbd3941c88bc1e4?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/56b0564d13413fec0713653cf76e91ba4d9c5fbbf6dbe0a8adbd3941c88bc1e4?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/56b0564d13413fec0713653cf76e91ba4d9c5fbbf6dbe0a8adbd3941c88bc1e4?s=96&d=mm&r=g","caption":"admin"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/56b0564d13413fec0713653cf76e91ba4d9c5fbbf6dbe0a8adbd3941c88bc1e4?s=96&d=mm&r=g"},"sameAs":["https:\/\/kishor10d.com\/blogs"],"url":"https:\/\/kishor10d.com\/blogs\/author\/kishor10d\/"}]}},"_links":{"self":[{"href":"https:\/\/kishor10d.com\/blogs\/wp-json\/wp\/v2\/posts\/41","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kishor10d.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kishor10d.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kishor10d.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kishor10d.com\/blogs\/wp-json\/wp\/v2\/comments?post=41"}],"version-history":[{"count":3,"href":"https:\/\/kishor10d.com\/blogs\/wp-json\/wp\/v2\/posts\/41\/revisions"}],"predecessor-version":[{"id":125,"href":"https:\/\/kishor10d.com\/blogs\/wp-json\/wp\/v2\/posts\/41\/revisions\/125"}],"wp:attachment":[{"href":"https:\/\/kishor10d.com\/blogs\/wp-json\/wp\/v2\/media?parent=41"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kishor10d.com\/blogs\/wp-json\/wp\/v2\/categories?post=41"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kishor10d.com\/blogs\/wp-json\/wp\/v2\/tags?post=41"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}