Page 1 of 1

hex counter

Posted: Tue Dec 13, 2005 3:46 pm
by flann
Is there any way to create a counter in hex? an example would be count from 0 - F.

Posted: Tue Dec 13, 2005 5:58 pm
by onion2k

Code: Select all

for ($x=0;$x<10000;$x++) {
  echo dechex($x);
}

Posted: Tue Dec 13, 2005 6:14 pm
by Chris Corbyn
onion is right.... PHP reads it as decimal but to use proper hex notation (more understandable to the developer) do this:

Your example:

Code: Select all

for ($x=0x00; $x<=0x0F; $x++)
{
    echo dechex($x).'<br />';
}