Page 1 of 1
convert hex to index
Posted: Mon Jan 14, 2008 7:09 pm
by mikeeeeeeey
Hi,
Where am I going wrong?
I know this is the wrong syntax for what I want to do, but I'm not sure how to write what I want to do. When I have $hex populated by a hexadecial such as #714e5f, I want to convert this to the index which is 7425631. doing...
works fine, but $hex is going to be constantly changing.....help!
Thanks for readin.
Re: convert hex to index
Posted: Mon Jan 14, 2008 7:24 pm
by Ambush Commander
You want
hex2dec(). The syntax you are attempting is not supported.
Re: convert hex to index
Posted: Mon Jan 14, 2008 7:39 pm
by jimthunderbird
Guess this will be up to your requirement.
Code: Select all
<?php
$hex_input = "714e5f";
$command = "\$index=0x".$hex_input.";";
eval($command);
print $index;
?>
hex2dec() is good too.
Re: convert hex to index
Posted: Mon Jan 14, 2008 7:41 pm
by Ambush Commander
I'm sorry, but I'm going to say, "Don't use that code." There is absolutely no reason why you need to bust out eval in this case.
Re: convert hex to index
Posted: Mon Jan 14, 2008 7:42 pm
by jimthunderbird
Ambush Commander wrote:I'm sorry, but I'm going to say, "Don't use that code." There is absolutely no reason why you need to bust out eval in this case.
Alright, then hex2dec() is good enough. I'm just thinking out loud.
Re: convert hex to index
Posted: Tue Jan 15, 2008 2:54 am
by Kieran Huggins
Someone here once said "if you need eval(), you're doing it wrong." I tend to agree!