PHP - Generating Hexadecimal values

  • alexislalas
  • Novice
  • Novice
  • No Avatar
  • Joined: Feb 27, 2007
  • Posts: 30
  • Status: Offline

Post May 18th, 2009, 11:50 am

Hello,
I have a pool of values I have to use, but I only have the first and last value of the range: 9CF90000-9CF910CB and I need all the values between them.

How can I get them or generate them?

Thanks!!
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post May 18th, 2009, 11:50 am

  • natas
  • PHP Ninja
  • Proficient
  • No Avatar
  • Joined: Mar 28, 2009
  • Posts: 305
  • Loc: AFK
  • Status: Offline

Post May 18th, 2009, 12:23 pm

I did a quick google search using hexadecimal, and it gave a javascript code to convert any number to hex...

If you put this in a loop somehow, starting with "X" and ending in "Y"...

Although, I don't know if it would work because I don't know javascript.
Custom Web Design
  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13455
  • Loc: Florida
  • Status: Offline

Post May 18th, 2009, 1:04 pm

Code: [ Select ]
for($i = 0x9CF90000; $i < 0x9CF910CB; $i++)
{
$hex = sprintf('%X', $i);
}
  1. for($i = 0x9CF90000; $i < 0x9CF910CB; $i++)
  2. {
  3. $hex = sprintf('%X', $i);
  4. }
Strong with this one, the sudo is.
  • alexislalas
  • Novice
  • Novice
  • No Avatar
  • Joined: Feb 27, 2007
  • Posts: 30
  • Status: Offline

Post May 21st, 2009, 8:25 am

awesome!!! thanks!!!

just some doubts... could you explain why the value has the 0x before and what sprintf('%X', $i); means?

thanks!
  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Joined: Sep 22, 2003
  • Posts: 6128
  • Loc: Seattle, WA
  • Status: Offline

Post May 21st, 2009, 8:42 am

http://us2.php.net/sprintf
The Beer Monocle. Classy.
  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13455
  • Loc: Florida
  • Status: Offline

Post May 21st, 2009, 11:05 am

alexislalas wrote:
... could you explain why the value has the 0x before ...


If you read about integers, you'll learn about the hexadecimal syntax I used.
http://www.php.net/manual/language.types.integer.php

I used that syntax because you were working with hexadecimals anyway. :)
Strong with this one, the sudo is.
  • alexislalas
  • Novice
  • Novice
  • No Avatar
  • Joined: Feb 27, 2007
  • Posts: 30
  • Status: Offline

Post May 21st, 2009, 3:31 pm

oh, ok, thanks to both!!

Post Information

  • Total Posts in this topic: 7 posts
  • Users browsing this forum: No registered users and 209 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.