hex counter

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
flann
Forum Commoner
Posts: 38
Joined: Tue Aug 23, 2005 10:48 pm

hex counter

Post by flann »

Is there any way to create a counter in hex? an example would be count from 0 - F.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Code: Select all

for ($x=0;$x<10000;$x++) {
  echo dechex($x);
}
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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 />';
}
Post Reply