Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Arno Welzel Newsgroups: comp.lang.php Subject: Re: Implied cast differs from explicit cast Date: Mon, 16 Jan 2012 08:42:27 +0100 Organization: A noiseless patient Spider Lines: 38 Message-ID: <4F13D4E3.3010208@arnowelzel.de> References: <4f1378ee$0$16741$882e7ee2@usenet-news.net> <4f139498$0$16818$882e7ee2@usenet-news.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Injection-Info: mx04.eternal-september.org; posting-host="6X7XqsRC4GQAmI7FQ3v4Fw"; logging-data="17417"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18ddxfp8pX9o6OJ8aS0pMUmhP71MYzmNpc=" User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:9.0) Gecko/20111222 Thunderbird/9.0.1 In-Reply-To: Cancel-Lock: sha1:uCJozbwyza3w5leL39WXsDFsgKY= Xref: x330-a1.tempe.blueboxinc.net comp.lang.php:4472 Jerry Stuckle, 2012-01-16 04:39: > On 1/15/2012 10:08 PM, lb wrote: >> jstucklex@attglobal.net wrote: >>> ... >>> No, it is not. '0x12' is a hex number, not an integer. (int)'0x12' >>> converts this correctly to 0. >> >> OK, but if (int)'0x12' is 0, why is '0x12'+0 == 18? >> >> Why are they different? Aren't they both doing 'string conversion to >> number'? > > As I said - '0x12' is a hex value, not an integer. You are trying to > convert it as if it were a string representation of an integer. The > implicit conversion recognizes it is a hex value and uses the > appropriate conversion. There is no difference between "hex value" and "integer" - both 0x12 and 18 are just different representations of the same value. The problem is that the explizit cast from string to int does not take this into account. Example: Result: 0 -- Arno Welzel http://arnowelzel.de http://de-rec-fahrrad.de