|
|
 |
BinDec (PHP 3, PHP 4 ) BinDec -- Convertit de binaire en décimal Descriptionint bindec ( string binary_string)
bindec() retourne la conversion d'un nombre
binaire représenté par la chaîne
binary_string en décimal.
bindec() convertit un nombre binaire en décimal.
Le plus grand nombre convertible a 31 bits à 1, soit
2147483647 en décimal.
Voir aussi
decbin().
User Contributed Notes BinDec |
 |
da_he4datthe-gurusdotde
17-Sep-2001 02:11 |
|
[Editor's Note:
Numeric values starting with 0 are interpreted as octal
(base eight) values. For example: 0101 is converts to
65
--zak@php.net]
i was quite confused while werking with
those bindec()/decbin() functions..
while
echo
decbin(bindec(1));
echo decbin(bindec(10));
echo
decbin(bindec(101));
just worked like expected,
echo
decbin(bindec(010));
returns just 0
and for any reason
echo
decbin(bindec(010010010));
returns 101000
i dont think this
is a bug (maybe theres some special reason 4 this?), but it took a
certain time till i noticed that
echo
decbin(bindec("010010010"));
works fine ...
hope
this helps ne1.
|
|
php at silisoftware dot com
01-Mar-2002 02:16 |
|
For converting larger-than-31-bit numbers:
function
Bin2Dec($binstring) { for ($i=0;$i<strlen($binstring);$i++)
{ $decvalue += ((int) substr($binstring, strlen($binstring) - $i - 1,
1)) * pow(2, $i); } return $decvalue; }
|
|
|
01-Mar-2002 04:43 |
|
The special reason 4 this is: (010) is an integer, left 0 is null, eg
010 = 10 ('010') is a string, eg '010' = '010'
cya
|
|
juancri at tagnet dot org
30-Oct-2002 11:16 |
|
> The special reason 4 this is: > (010) is an integer, left 0 is
null, eg 010 = 10 > ('010') is a string, eg '010' = '010'
In
binary, just like with decimals, the left 0's are nulls.
in
Decimal: 010 = 10 in Binary: 010 = 10 too :o)
> echo
decbin(bindec(010010010)); > returns 101000
010010010 is a
octal number. It's eq. to 2101256 (decimal). decbin(bindec(010010010)) is
101000 because 010010010 = 2101256.
That's all =)
|
|
 |
| |