Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert binary string to integer in php

In php how do I convert a string "1010101010" into the integer value represented by this binary number?

eg "10" would go to 2, "101" would go to 5

like image 342
wheresrhys Avatar asked Oct 31 '25 02:10

wheresrhys


2 Answers

Use bindec() function to convert from binary to decimal:

$value = bindec("10101011010101");
like image 188
Crozin Avatar answered Nov 01 '25 18:11

Crozin


Try the bindec() function.

like image 42
István Ujj-Mészáros Avatar answered Nov 01 '25 17:11

István Ujj-Mészáros