Re: base_convert bug?

From: Date: Mon, 28 Jul 2014 10:13:30 +0000
Subject: Re: base_convert bug?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-323671@lists.php.net to get a copy of this message
On 28 July 2014 10:43:29 BST, "Radek Krejča" <radek.krejca@starnet.cz> 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

« previous php.general (#323671) next »