Resolved: PHP and Hexadecimal

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
User avatar
thomas777neo
Forum Contributor
Posts: 214
Joined: Mon Mar 10, 2003 6:12 am
Location: Johannesburg,South Africa

Resolved: PHP and Hexadecimal

Post by thomas777neo »

Good Day

Does anyone have a class that outputs the iteration of hex values according to a range?

E.g. 520-52f

I need to get a list of the values within that range.

Like

520
521
522
... for the 16 values
Last edited by thomas777neo on Mon Jul 16, 2007 7:15 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You can use range() + array_map() + dechex()
User avatar
thomas777neo
Forum Contributor
Posts: 214
Joined: Mon Mar 10, 2003 6:12 am
Location: Johannesburg,South Africa

Post by thomas777neo »

Thanks feyd, never had to use the range function yet (quite an obvious one)

Here is the quick and dirty version so far:

Code: Select all

$start_range = hexdec("0520");
$end_range = hexdec("052f");
	
foreach (range($start_range,$end_range) as $number) 
{
    $dechex = dechex($number);
} // foreach (range($start_range,$end_range) as $number)
Works just fine for now. Thanks again.
Post Reply