Re: base_convert bug?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 28 July 2014 10:43:29 BST, "Radek Krejča" <radek.krejca@xxxxxxxxxx> wrote:
>Hello,
>
>function base convert from base(16) to base(2) returns wrong value
>whenever the binary string starts with zeros
>it eliminates all 0s in the left of the string until first (1)
>
>example :
>base_convert("10",16,2);
>
>//return value 10000
>//correct value 00010000
>
>Is it bug? Thank you.
>
>Radek

That's not a bug, they're both the same number. Leading zeros are always ignored in number systems, and PHP doesn't attempt to format it assuming and specific word size. Try the same conversion in your computers calculator.

To format the number as you wish for output, use printf or sprintf to pad with leading zeros.
Thanks,
Ash

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux