Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,971 questions

51,913 answers

573 users

How to print binary representation (bits) of a number in PHP

2 Answers

0 votes
echo decbin(9) . "<br />";
echo decbin(13) . "<br />";
echo decbin(15) . "<br />";
echo decbin(20) . "<br />";

 
/*
run:

1001
1101
1111
10100

*/

 



answered Oct 10, 2016 by avibootz
0 votes
echo dec2bin(9) . "<br />";
echo dec2bin(13) . "<br />";
echo dec2bin(15) . "<br />";
echo dec2bin(20) . "<br />";

function dec2bin($dec, $pad = 8) 
{
    return str_pad(decbin($dec), $pad, "0", STR_PAD_LEFT);
}
 
/*
run:

00001001
00001101
00001111
00010100

*/

 



answered Oct 10, 2016 by avibootz
...