FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Implied cast differs from explicit cast
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Implied cast differs from explicit cast [message #176657] Mon, 16 January 2012 01:10 Go to next message
lb is currently offline  lb
Messages: 4
Registered: January 2012
Karma: 0
Junior Member
When converting some strings to int (or double), I am finding that
an implied cast get different results from explicit cast. This happens
when the string contains a hex representation. The implied cast converts
the hex value, but the explicit cast returns 0. The manual under "String
conversion to numbers" says nothing about it allowing hex values. This is
with PHP-5.3.9 and older.

Script:
<?php
$s1 = '0x12';
$t1 = $s1 + 0;
echo "Implied cast t1=$t1\n";
$t2 = (int)$s1 + 0;
echo "Explicit cast t2=$t2\n";

Output:
Implied cast t1=18
Explicit cast t2=0


I think this is odd. A side problem is that is_numeric('0x12') is true, but
((int)'0x12') is 0. Does anyone think this a bug?
Re: Implied cast differs from explicit cast [message #176658 is a reply to message #176657] Mon, 16 January 2012 01:51 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 1/15/2012 8:10 PM, lb wrote:
> When converting some strings to int (or double), I am finding that
> an implied cast get different results from explicit cast. This happens
> when the string contains a hex representation. The implied cast converts
> the hex value, but the explicit cast returns 0. The manual under "String
> conversion to numbers" says nothing about it allowing hex values. This is
> with PHP-5.3.9 and older.
>
> Script:
> <?php
> $s1 = '0x12';
> $t1 = $s1 + 0;
> echo "Implied cast t1=$t1\n";
> $t2 = (int)$s1 + 0;
> echo "Explicit cast t2=$t2\n";
>
> Output:
> Implied cast t1=18
> Explicit cast t2=0
>
>
> I think this is odd. A side problem is that is_numeric('0x12') is true, but
> ((int)'0x12') is 0. Does anyone think this a bug?
>
>

No, it is not. '0x12' is a hex number, not an integer. (int)'0x12'
converts this correctly to 0.

If you want to convert a hex number to an integer, you need to use
hexdec(), which is what the implied conversion does.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Implied cast differs from explicit cast [message #176659 is a reply to message #176658] Mon, 16 January 2012 03:08 Go to previous messageGo to next message
lb is currently offline  lb
Messages: 4
Registered: January 2012
Karma: 0
Junior Member
jstucklex(at)attglobal(dot)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'?
Re: Implied cast differs from explicit cast [message #176660 is a reply to message #176659] Mon, 16 January 2012 03:39 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 1/15/2012 10:08 PM, lb wrote:
> jstucklex(at)attglobal(dot)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.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Implied cast differs from explicit cast [message #176662 is a reply to message #176660] Mon, 16 January 2012 07:42 Go to previous messageGo to next message
Arno Welzel is currently offline  Arno Welzel
Messages: 317
Registered: October 2011
Karma: 0
Senior Member
Jerry Stuckle, 2012-01-16 04:39:

> On 1/15/2012 10:08 PM, lb wrote:
>> jstucklex(at)attglobal(dot)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:

<?php
$a = 0x12;
$b = 18;
print $a-$b;
?>

Result:

0

--
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de
Re: Implied cast differs from explicit cast [message #176666 is a reply to message #176657] Mon, 16 January 2012 08:49 Go to previous messageGo to next message
M. Strobel is currently offline  M. Strobel
Messages: 386
Registered: December 2011
Karma: 0
Senior Member
Am 16.01.2012 02:10, schrieb lb:
> When converting some strings to int (or double), I am finding that
> an implied cast get different results from explicit cast. This happens
> when the string contains a hex representation. The implied cast converts
> the hex value, but the explicit cast returns 0. The manual under "String
> conversion to numbers" says nothing about it allowing hex values. This is
> with PHP-5.3.9 and older.
>
> Script:
> <?php
> $s1 = '0x12';
> $t1 = $s1 + 0;
> echo "Implied cast t1=$t1\n";
> $t2 = (int)$s1 + 0;
> echo "Explicit cast t2=$t2\n";
>
> Output:
> Implied cast t1=18
> Explicit cast t2=0
>
>
> I think this is odd. A side problem is that is_numeric('0x12') is true, but
> ((int)'0x12') is 0. Does anyone think this a bug?

I think it is odd. The notion of "hex string" does not make sense of it.

/Str.
Re: Implied cast differs from explicit cast [message #176667 is a reply to message #176662] Mon, 16 January 2012 09:04 Go to previous messageGo to next message
Curtis Dyer is currently offline  Curtis Dyer
Messages: 34
Registered: January 2011
Karma: 0
Member
Arno Welzel <usenet(at)arnowelzel(dot)de> wrote:

> Jerry Stuckle, 2012-01-16 04:39:
>
>> On 1/15/2012 10:08 PM, lb wrote:
>>> jstucklex(at)attglobal(dot)net wrote:
>>>> ...
>>>> No, it is not. '0x12' is a hex number, not an integer.
>>>> (int)'0x12' converts this correctly to 0.

As Arno points out, the hex value *is* an integer (once converted
from a string, in this case).

>>> 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.

The problem, as far as I can tell, has to do with the implicit
behavior of the "(int)$str" cast. Its default behavior seems to be
identicle to:

/* operates on base ten values; 10 is the default base when the
* second parameter is omitted. */
intval($str, 10);

So, '0x12' is obviously then considered an invalid base ten
integer, thus the expression, "(int)'0x12'" yields 0.

If you want to convert a hex value, either use hexdec() or use:

intval($str, 16);

Note, however, the behavior of hexdec($str) and intval($str, 16)
are not identicle! In some cases, hexdec() may be preferable, as
it will attempt to represent values too large for integers as
floating-point values. It also disregards non-hex value
characters in the string.

RTM here:

<http://php.net/intval>
<http://php.net/hexdec>

--
Curtis Dyer
<?$x='<?$x=%c%s%c;printf($x,39,$x,39);?>';printf($x,39,$x,39);?>
Re: Implied cast differs from explicit cast [message #176669 is a reply to message #176657] Mon, 16 January 2012 10:48 Go to previous messageGo to next message
alvaro.NOSPAMTHANX is currently offline  alvaro.NOSPAMTHANX
Messages: 277
Registered: September 2010
Karma: 0
Senior Member
El 16/01/2012 2:10, lb escribió/wrote:
> When converting some strings to int (or double), I am finding that
> an implied cast get different results from explicit cast. This happens
> when the string contains a hex representation. The implied cast converts
> the hex value, but the explicit cast returns 0. The manual under "String
> conversion to numbers" says nothing about it allowing hex values. This is
> with PHP-5.3.9 and older.
>
> Script:
> <?php
> $s1 = '0x12';
> $t1 = $s1 + 0;
> echo "Implied cast t1=$t1\n";
> $t2 = (int)$s1 + 0;
> echo "Explicit cast t2=$t2\n";
>
> Output:
> Implied cast t1=18
> Explicit cast t2=0
>
>
> I think this is odd. A side problem is that is_numeric('0x12') is true, but
> ((int)'0x12') is 0. Does anyone think this a bug?

Interesting subject... There are actually two different sections in the
PHP manual:

*************************************************************************

Explicit cast:

http://es2.php.net/manual/en/language.types.integer.php#language.types.inte ger.casting

«To explicitly convert a value to integer, use either the (int) or
(integer) casts. [...] A value can also be converted to integer with the
intval() function.»

It admit it's not 100% clear but I have the impression that the
underlying code is just the same and intval():

http://es2.php.net/manual/en/function.intval.php>

*************************************************************************

Implicit cast:

http://es2.php.net/manual/en/language.types.string.php#language.types.strin g.conversion

«When a string is evaluated in a numeric context, the resulting value
and type are determined as follows.»

First difference is that you don't necessarily get an integer:

«If the string does not contain any of the characters '.', 'e', or 'E'
and the numeric value fits into integer type limits (as defined by
PHP_INT_MAX), the string will be evaluated as an integer. In all other
cases it will be evaluated as a float.»

Second difference is that a standard C library is mentioned:

«For more information on this conversion, see the Unix manual page for
strtod(3).»

.... thus we can get further details:

http://linux.die.net/man/3/strtod

«The expected form of the (initial portion of the) string is optional
leading white space as recognized by isspace(3), an optional plus ('+')
or minus sign ('-') and then either (i) a decimal number, or (ii) a
hexadecimal number, or (iii) an infinity, or (iv) a NAN (not-a-number).»

*************************************************************************

I believe the most relevant difference is that:

- intval() accepts any base but does not guess (defaults to 10)
- strtod() only accepts base 10 and 16 and does guess

.... which explains your issue.

--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
Re: Implied cast differs from explicit cast [message #176671 is a reply to message #176662] Mon, 16 January 2012 13:25 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 1/16/2012 2:42 AM, Arno Welzel wrote:
> Jerry Stuckle, 2012-01-16 04:39:
>
>> On 1/15/2012 10:08 PM, lb wrote:
>>> jstucklex(at)attglobal(dot)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:
>
> <?php
> $a = 0x12;
> $b = 18;
> print $a-$b;
> ?>
>
> Result:
>
> 0
>

In C/C++ there is no difference. However, in PHP there is. The 'x' is
not a valid decimal character, so (int) '0x12' returns 0.

The correct function to use when converting hexadecimal strings is hexdec().

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Implied cast differs from explicit cast [message #176672 is a reply to message #176659] Mon, 16 January 2012 13:28 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
lb wrote:
> jstucklex(at)attglobal(dot)net wrote:
>> ...
>> No, it is not. '0x12' is a hex number, not an integer. (int)'0x12'
>> converts this correctly to 0.

Looks like Jerry doesn't know what an integer is either.

A hex number of course *is* an integer, unless its a hex representation
of floating point.

Killfile the prat like I have.


>
> 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'?

Don't expect Jerry to have a clue

because its either an integer number or a non numeric string?

I have given up trying to second guess PHP in casting.

One keeps things very simple as with a 2 year old (or jerry) when using PHP.

It can understand 18

It can understand 'eighteeen'

Lord knows what it does with '18'


As for 0x12...man, you are pushing the boat out, there.

Stop expecting PHP to be more than it is, a quick hack that writes good
web pages faster than almost anything else.

If you want a language that has a rule set and sticks to it rigidly,
that's C.
Re: Implied cast differs from explicit cast [message #176673 is a reply to message #176672] Mon, 16 January 2012 13:45 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 1/16/2012 8:28 AM, The Natural Philosopher wrote:
> lb wrote:
>> jstucklex(at)attglobal(dot)net wrote:
>>> ...
>>> No, it is not. '0x12' is a hex number, not an integer. (int)'0x12'
>>> converts this correctly to 0.
>
> Looks like Jerry doesn't know what an integer is either.
>
> A hex number of course *is* an integer, unless its a hex representation
> of floating point.
>
> Killfile the prat like I have.
>
>

0x12 is not an integer. It is a hexadecimal value.

It can have the same bit pattern as an integer - but it can also have
the same bit pattern as a character (Ctrl-R, to be exact).

>>
>> 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'?
>
> Don't expect Jerry to have a clue
>
> because its either an integer number or a non numeric string?
>
> I have given up trying to second guess PHP in casting.
>
> One keeps things very simple as with a 2 year old (or jerry) when using
> PHP.
>
> It can understand 18
>
> It can understand 'eighteeen'
>
> Lord knows what it does with '18'
>
>
> As for 0x12...man, you are pushing the boat out, there.
>
> Stop expecting PHP to be more than it is, a quick hack that writes good
> web pages faster than almost anything else.
>
> If you want a language that has a rule set and sticks to it rigidly,
> that's C.
>

You're mixing C/C++ and PHP. They are not the same language.



--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Implied cast differs from explicit cast [message #176674 is a reply to message #176671] Mon, 16 January 2012 18:51 Go to previous messageGo to next message
M. Strobel is currently offline  M. Strobel
Messages: 386
Registered: December 2011
Karma: 0
Senior Member
Am 16.01.2012 14:25, schrieb Jerry Stuckle:
> On 1/16/2012 2:42 AM, Arno Welzel wrote:
>> Jerry Stuckle, 2012-01-16 04:39:
>>
>>> On 1/15/2012 10:08 PM, lb wrote:
>>>> jstucklex(at)attglobal(dot)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.
>>
--cut
>>
>
> In C/C++ there is no difference. However, in PHP there is. The 'x' is not a valid
> decimal character, so (int) '0x12' returns 0.
>
> The correct function to use when converting hexadecimal strings is hexdec().

The last two sentences sound correct to me, so far. Looks like you are trying to
think like PHP.

But this does not make things better here, because PHP (the Zend T_INT_CAST) is just
half-witted here.

/Str.
Re: Implied cast differs from explicit cast [message #176679 is a reply to message #176669] Tue, 17 January 2012 02:35 Go to previous messageGo to next message
lb is currently offline  lb
Messages: 4
Registered: January 2012
Karma: 0
Junior Member
Thanks to all who replied, more or less...

I was not trying to convert hex to decimal or any such thing. I was
cleaning up some code that looked something like this:

if (is_numeric($data[$i])) {
$val = (double)$data[$i++];
...
} else {
$i++;
}

I changed it to:
if (is_numeric($val = $data[$i++])) {
...
}

During testing I found that I could get different results within the
block with $val used as a numeric value in calculations. The difference
was when a string containing a hex value was used in the data array.
This is odd behavior, and inconsistant, in my opinion, and might be
considered a PHP bug.
Re: Implied cast differs from explicit cast [message #176681 is a reply to message #176673] Tue, 17 January 2012 05:59 Go to previous messageGo to next message
Arno Welzel is currently offline  Arno Welzel
Messages: 317
Registered: October 2011
Karma: 0
Senior Member
Jerry Stuckle, 2012-01-16 14:45:

> On 1/16/2012 8:28 AM, The Natural Philosopher wrote:
>> lb wrote:
>>> jstucklex(at)attglobal(dot)net wrote:
>>>> ...
>>>> No, it is not. '0x12' is a hex number, not an integer. (int)'0x12'
>>>> converts this correctly to 0.
>>
>> Looks like Jerry doesn't know what an integer is either.
>>
>> A hex number of course *is* an integer, unless its a hex representation
>> of floating point.
>>
>> Killfile the prat like I have.
>>
>>
>
> 0x12 is not an integer. It is a hexadecimal value.

No, 0x12 (and *not* "0x12") is the hexadecimal *representation* of the
value 18. There is no thing like "hexadecimal value" and "0x12" is a
*string* and not a number at all.

In fact PHP only knows to types of numbers: integers and floating point.
There is no "hexadecimal" data type.

> It can have the same bit pattern as an integer - but it can also have
> the same bit pattern as a character (Ctrl-R, to be exact).

Which also applies to the value 18 - this can also be the value of a
character.

Example:

<?php
$a = 0x12;

print $a;
?>

Result:

Value of $a: 18, type of $a: integer

So you see 0x12 *is* an integer.

Of course "0x12" (including the quotes) is a string and *converting* the
string to a number may need attention to the representation of the
number within the string.


--
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de
Re: Implied cast differs from explicit cast [message #176682 is a reply to message #176681] Tue, 17 January 2012 06:00 Go to previous messageGo to next message
Arno Welzel is currently offline  Arno Welzel
Messages: 317
Registered: October 2011
Karma: 0
Senior Member
Arno Welzel, 2012-01-17 06:59:

> Jerry Stuckle, 2012-01-16 14:45:
>
>> On 1/16/2012 8:28 AM, The Natural Philosopher wrote:
>>> lb wrote:
>>>> jstucklex(at)attglobal(dot)net wrote:
>>>> > ...
>>>> > No, it is not. '0x12' is a hex number, not an integer. (int)'0x12'
>>>> > converts this correctly to 0.
>>>
>>> Looks like Jerry doesn't know what an integer is either.
>>>
>>> A hex number of course *is* an integer, unless its a hex representation
>>> of floating point.
>>>
>>> Killfile the prat like I have.
>>>
>>>
>>
>> 0x12 is not an integer. It is a hexadecimal value.
>
> No, 0x12 (and *not* "0x12") is the hexadecimal *representation* of the
> value 18. There is no thing like "hexadecimal value" and "0x12" is a
> *string* and not a number at all.
>
> In fact PHP only knows to types of numbers: integers and floating point.
> There is no "hexadecimal" data type.
>
>> It can have the same bit pattern as an integer - but it can also have
>> the same bit pattern as a character (Ctrl-R, to be exact).
>
> Which also applies to the value 18 - this can also be the value of a
> character.
>
> Example:
>
> <?php
> $a = 0x12;
>
> print $a;
> ?>
>
> Result:
>
> Value of $a: 18, type of $a: integer

Sorry - the example was not complete:

<?php
$a = 0x12;

$a = intval($a, 16);

print 'Value of $a: ' . $a . ', type of $a: ' . gettype($a);
?>



--
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de
Re: Implied cast differs from explicit cast [message #176686 is a reply to message #176681] Tue, 17 January 2012 13:16 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 1/17/2012 12:59 AM, Arno Welzel wrote:
> Jerry Stuckle, 2012-01-16 14:45:
>
>> On 1/16/2012 8:28 AM, The Natural Philosopher wrote:
>>> lb wrote:
>>>> jstucklex(at)attglobal(dot)net wrote:
>>>> > ...
>>>> > No, it is not. '0x12' is a hex number, not an integer. (int)'0x12'
>>>> > converts this correctly to 0.
>>>
>>> Looks like Jerry doesn't know what an integer is either.
>>>
>>> A hex number of course *is* an integer, unless its a hex representation
>>> of floating point.
>>>
>>> Killfile the prat like I have.
>>>
>>>
>>
>> 0x12 is not an integer. It is a hexadecimal value.
>
> No, 0x12 (and *not* "0x12") is the hexadecimal *representation* of the
> value 18. There is no thing like "hexadecimal value" and "0x12" is a
> *string* and not a number at all.
>

No, it is a hexadecimal value. It may be an integer, it may be a
character, it may be a set of flags... It does not have to be an integer.

> In fact PHP only knows to types of numbers: integers and floating point.
> There is no "hexadecimal" data type.
>

Excuse me - there is. See hexdec().

>> It can have the same bit pattern as an integer - but it can also have
>> the same bit pattern as a character (Ctrl-R, to be exact).
>
> Which also applies to the value 18 - this can also be the value of a
> character.
>
> Example:
>
> <?php
> $a = 0x12;
>
> print $a;
> ?>
>
> Result:
>
> Value of $a: 18, type of $a: integer
>
> So you see 0x12 *is* an integer.
>
> Of course "0x12" (including the quotes) is a string and *converting* the
> string to a number may need attention to the representation of the
> number within the string.
>
>

All it is is a representation of bits in a byte. How it is used
determines the datatype.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Implied cast differs from explicit cast [message #176687 is a reply to message #176682] Tue, 17 January 2012 13:17 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 1/17/2012 1:00 AM, Arno Welzel wrote:
> Arno Welzel, 2012-01-17 06:59:
>
>> Jerry Stuckle, 2012-01-16 14:45:
>>
>>> On 1/16/2012 8:28 AM, The Natural Philosopher wrote:
>>>> lb wrote:
>>>> > jstucklex(at)attglobal(dot)net wrote:
>>>> >> ...
>>>> >> No, it is not. '0x12' is a hex number, not an integer. (int)'0x12'
>>>> >> converts this correctly to 0.
>>>>
>>>> Looks like Jerry doesn't know what an integer is either.
>>>>
>>>> A hex number of course *is* an integer, unless its a hex representation
>>>> of floating point.
>>>>
>>>> Killfile the prat like I have.
>>>>
>>>>
>>>
>>> 0x12 is not an integer. It is a hexadecimal value.
>>
>> No, 0x12 (and *not* "0x12") is the hexadecimal *representation* of the
>> value 18. There is no thing like "hexadecimal value" and "0x12" is a
>> *string* and not a number at all.
>>
>> In fact PHP only knows to types of numbers: integers and floating point.
>> There is no "hexadecimal" data type.
>>
>>> It can have the same bit pattern as an integer - but it can also have
>>> the same bit pattern as a character (Ctrl-R, to be exact).
>>
>> Which also applies to the value 18 - this can also be the value of a
>> character.
>>
>> Example:
>>
>> <?php
>> $a = 0x12;
>>
>> print $a;
>> ?>
>>
>> Result:
>>
>> Value of $a: 18, type of $a: integer
>
> Sorry - the example was not complete:
>
> <?php
> $a = 0x12;
>
> $a = intval($a, 16);
>
> print 'Value of $a: ' . $a . ', type of $a: ' . gettype($a);
> ?>
>
>
>

Sure. You explicitly converted the hexadecimal value to an integer.
What do you expect?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Implied cast differs from explicit cast [message #176707 is a reply to message #176686] Thu, 19 January 2012 12:36 Go to previous messageGo to next message
Arno Welzel is currently offline  Arno Welzel
Messages: 317
Registered: October 2011
Karma: 0
Senior Member
Jerry Stuckle, 2012-01-17 14:16:

> On 1/17/2012 12:59 AM, Arno Welzel wrote:
>> Jerry Stuckle, 2012-01-16 14:45:
>>
>>> On 1/16/2012 8:28 AM, The Natural Philosopher wrote:
>>>> lb wrote:
>>>> > jstucklex(at)attglobal(dot)net wrote:
>>>> >> ...
>>>> >> No, it is not. '0x12' is a hex number, not an integer. (int)'0x12'
>>>> >> converts this correctly to 0.
>>>>
>>>> Looks like Jerry doesn't know what an integer is either.
>>>>
>>>> A hex number of course *is* an integer, unless its a hex representation
>>>> of floating point.
>>>>
>>>> Killfile the prat like I have.
>>>>
>>>>
>>>
>>> 0x12 is not an integer. It is a hexadecimal value.
>>
>> No, 0x12 (and *not* "0x12") is the hexadecimal *representation* of the
>> value 18. There is no thing like "hexadecimal value" and "0x12" is a
>> *string* and not a number at all.
>>
>
> No, it is a hexadecimal value. It may be an integer, it may be a
> character, it may be a set of flags... It does not have to be an integer.
>
>> In fact PHP only knows to types of numbers: integers and floating point.
>> There is no "hexadecimal" data type.
>>
>
> Excuse me - there is. See hexdec().

<http://php.net/manual/en/function.hexdec.php>

You don't know what a data type is? Do you?

See <http://www.php.net/manual/en/language.types.php> and show me, where
the "hexadecimal data type" is explained.

m(


--
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de
Re: Implied cast differs from explicit cast [message #176708 is a reply to message #176707] Thu, 19 January 2012 12:39 Go to previous messageGo to next message
Arno Welzel is currently offline  Arno Welzel
Messages: 317
Registered: October 2011
Karma: 0
Senior Member
Arno Welzel, 2012-01-19 13:36:

> Jerry Stuckle, 2012-01-17 14:16:
>
>> On 1/17/2012 12:59 AM, Arno Welzel wrote:
>>> Jerry Stuckle, 2012-01-16 14:45:
>>>
>>>> On 1/16/2012 8:28 AM, The Natural Philosopher wrote:
>>>> > lb wrote:
>>>> >> jstucklex(at)attglobal(dot)net wrote:
>>>> >>> ...
>>>> >>> No, it is not. '0x12' is a hex number, not an integer. (int)'0x12'
>>>> >>> converts this correctly to 0.
>>>> >
>>>> > Looks like Jerry doesn't know what an integer is either.
>>>> >
>>>> > A hex number of course *is* an integer, unless its a hex representation
>>>> > of floating point.
>>>> >
>>>> > Killfile the prat like I have.
>>>> >
>>>> >
>>>>
>>>> 0x12 is not an integer. It is a hexadecimal value.
>>>
>>> No, 0x12 (and *not* "0x12") is the hexadecimal *representation* of the
>>> value 18. There is no thing like "hexadecimal value" and "0x12" is a
>>> *string* and not a number at all.
>>>
>>
>> No, it is a hexadecimal value. It may be an integer, it may be a
>> character, it may be a set of flags... It does not have to be an integer.
>>
>>> In fact PHP only knows to types of numbers: integers and floating point.
>>> There is no "hexadecimal" data type.
>>>
>>
>> Excuse me - there is. See hexdec().
>
> <http://php.net/manual/en/function.hexdec.php>
>
> You don't know what a data type is? Do you?
>
> See <http://www.php.net/manual/en/language.types.php> and show me, where
> the "hexadecimal data type" is explained.

And you should read the section about *integer* literal in
<http://www.php.net/manual/en/language.types.integer.php> very carefully.

There is no thing as "conversion of hexadecimal values to an integer".

EOD for me.


--
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de
Re: Implied cast differs from explicit cast [message #176714 is a reply to message #176707] Thu, 19 January 2012 14:05 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 1/19/2012 7:36 AM, Arno Welzel wrote:
> Jerry Stuckle, 2012-01-17 14:16:
>
>> On 1/17/2012 12:59 AM, Arno Welzel wrote:
>>> Jerry Stuckle, 2012-01-16 14:45:
>>>
>>>> On 1/16/2012 8:28 AM, The Natural Philosopher wrote:
>>>> > lb wrote:
>>>> >> jstucklex(at)attglobal(dot)net wrote:
>>>> >>> ...
>>>> >>> No, it is not. '0x12' is a hex number, not an integer. (int)'0x12'
>>>> >>> converts this correctly to 0.
>>>> >
>>>> > Looks like Jerry doesn't know what an integer is either.
>>>> >
>>>> > A hex number of course *is* an integer, unless its a hex representation
>>>> > of floating point.
>>>> >
>>>> > Killfile the prat like I have.
>>>> >
>>>> >
>>>>
>>>> 0x12 is not an integer. It is a hexadecimal value.
>>>
>>> No, 0x12 (and *not* "0x12") is the hexadecimal *representation* of the
>>> value 18. There is no thing like "hexadecimal value" and "0x12" is a
>>> *string* and not a number at all.
>>>
>>
>> No, it is a hexadecimal value. It may be an integer, it may be a
>> character, it may be a set of flags... It does not have to be an integer.
>>
>>> In fact PHP only knows to types of numbers: integers and floating point.
>>> There is no "hexadecimal" data type.
>>>
>>
>> Excuse me - there is. See hexdec().
>
> <http://php.net/manual/en/function.hexdec.php>
>
> You don't know what a data type is? Do you?
>
> See<http://www.php.net/manual/en/language.types.php> and show me, where
> the "hexadecimal data type" is explained.
>
> m(
>
>

Learn to read. I never said anything about a hexadecimal datatype.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Implied cast differs from explicit cast [message #176715 is a reply to message #176708] Thu, 19 January 2012 14:06 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 1/19/2012 7:39 AM, Arno Welzel wrote:
> Arno Welzel, 2012-01-19 13:36:
>
>> Jerry Stuckle, 2012-01-17 14:16:
>>
>>> On 1/17/2012 12:59 AM, Arno Welzel wrote:
>>>> Jerry Stuckle, 2012-01-16 14:45:
>>>>
>>>> > On 1/16/2012 8:28 AM, The Natural Philosopher wrote:
>>>> >> lb wrote:
>>>> >>> jstucklex(at)attglobal(dot)net wrote:
>>>> >>>> ...
>>>> >>>> No, it is not. '0x12' is a hex number, not an integer. (int)'0x12'
>>>> >>>> converts this correctly to 0.
>>>> >>
>>>> >> Looks like Jerry doesn't know what an integer is either.
>>>> >>
>>>> >> A hex number of course *is* an integer, unless its a hex representation
>>>> >> of floating point.
>>>> >>
>>>> >> Killfile the prat like I have.
>>>> >>
>>>> >>
>>>> >
>>>> > 0x12 is not an integer. It is a hexadecimal value.
>>>>
>>>> No, 0x12 (and *not* "0x12") is the hexadecimal *representation* of the
>>>> value 18. There is no thing like "hexadecimal value" and "0x12" is a
>>>> *string* and not a number at all.
>>>>
>>>
>>> No, it is a hexadecimal value. It may be an integer, it may be a
>>> character, it may be a set of flags... It does not have to be an integer.
>>>
>>>> In fact PHP only knows to types of numbers: integers and floating point.
>>>> There is no "hexadecimal" data type.
>>>>
>>>
>>> Excuse me - there is. See hexdec().
>>
>> <http://php.net/manual/en/function.hexdec.php>
>>
>> You don't know what a data type is? Do you?
>>
>> See<http://www.php.net/manual/en/language.types.php> and show me, where
>> the "hexadecimal data type" is explained.
>
> And you should read the section about *integer* literal in
> <http://www.php.net/manual/en/language.types.integer.php> very carefully.
>
> There is no thing as "conversion of hexadecimal values to an integer".
>
> EOD for me.
>
>

That's good. Come on back when you learn to read. '0x12' is not an
integer.

But then you've already proven you have no idea what you're talking
about. All you're doing is making yourself look even stoopider.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Implied cast differs from explicit cast [message #176717 is a reply to message #176707] Thu, 19 January 2012 15:01 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
Arno Welzel wrote:
> Jerry Stuckle, 2012-01-17 14:16:
>
>> On 1/17/2012 12:59 AM, Arno Welzel wrote:
>>> Jerry Stuckle, 2012-01-16 14:45:
>>>
>>>> On 1/16/2012 8:28 AM, The Natural Philosopher wrote:
>>>> > lb wrote:
>>>> >> jstucklex(at)attglobal(dot)net wrote:
>>>> >>> ...
>>>> >>> No, it is not. '0x12' is a hex number, not an integer. (int)'0x12'
>>>> >>> converts this correctly to 0.
>>>> > Looks like Jerry doesn't know what an integer is either.
>>>> >
>>>> > A hex number of course *is* an integer, unless its a hex representation
>>>> > of floating point.
>>>> >
>>>> > Killfile the prat like I have.
>>>> >
>>>> >
>>>> 0x12 is not an integer. It is a hexadecimal value.
>>> No, 0x12 (and *not* "0x12") is the hexadecimal *representation* of the
>>> value 18. There is no thing like "hexadecimal value" and "0x12" is a
>>> *string* and not a number at all.
>>>
>> No, it is a hexadecimal value. It may be an integer, it may be a
>> character, it may be a set of flags... It does not have to be an integer.
>>
>>> In fact PHP only knows to types of numbers: integers and floating point.
>>> There is no "hexadecimal" data type.
>>>
>> Excuse me - there is. See hexdec().
>
> <http://php.net/manual/en/function.hexdec.php>
>
> You don't know what a data type is? Do you?
>

No, it's Jerrykins.

You expect too much.......

> See <http://www.php.net/manual/en/language.types.php> and show me, where
> the "hexadecimal data type" is explained.
>

........Including the ability to say 'er yes, I was wrong' with grace, or
at all.


> m(
>
>
Re: Implied cast differs from explicit cast [message #176718 is a reply to message #176717] Thu, 19 January 2012 19:41 Go to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 1/19/2012 10:01 AM, The Natural Philosopher wrote:
> Arno Welzel wrote:
>> Jerry Stuckle, 2012-01-17 14:16:
>>
>>> On 1/17/2012 12:59 AM, Arno Welzel wrote:
>>>> Jerry Stuckle, 2012-01-16 14:45:
>>>>
>>>> > On 1/16/2012 8:28 AM, The Natural Philosopher wrote:
>>>> >> lb wrote:
>>>> >>> jstucklex(at)attglobal(dot)net wrote:
>>>> >>>> ...
>>>> >>>> No, it is not. '0x12' is a hex number, not an integer. (int)'0x12'
>>>> >>>> converts this correctly to 0.
>>>> >> Looks like Jerry doesn't know what an integer is either.
>>>> >>
>>>> >> A hex number of course *is* an integer, unless its a hex
>>>> >> representation
>>>> >> of floating point.
>>>> >>
>>>> >> Killfile the prat like I have.
>>>> >>
>>>> >>
>>>> > 0x12 is not an integer. It is a hexadecimal value.
>>>> No, 0x12 (and *not* "0x12") is the hexadecimal *representation* of the
>>>> value 18. There is no thing like "hexadecimal value" and "0x12" is a
>>>> *string* and not a number at all.
>>>>
>>> No, it is a hexadecimal value. It may be an integer, it may be a
>>> character, it may be a set of flags... It does not have to be an
>>> integer.
>>>
>>>> In fact PHP only knows to types of numbers: integers and floating
>>>> point.
>>>> There is no "hexadecimal" data type.
>>>>
>>> Excuse me - there is. See hexdec().
>>
>> <http://php.net/manual/en/function.hexdec.php>
>>
>> You don't know what a data type is? Do you?
>>
>
> No, it's Jerrykins.
>
> You expect too much.......
>
>> See <http://www.php.net/manual/en/language.types.php> and show me, where
>> the "hexadecimal data type" is explained.
>>
>
> .......Including the ability to say 'er yes, I was wrong' with grace, or
> at all.
>
>
>> m(
>>
>>

Another troll who can't read.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Open Source Development
Next Topic: error from phpadmin
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 10 12:32:43 GMT 2024

Total time taken to generate the page: 0.02453 seconds