PHP - Generating Hexadecimal values

  • alexislalas
  • Novice
  • Novice
  • alexislalas
  • Posts: 32

Post 3+ Months Ago

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
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • natas
  • PHP Ninja
  • Proficient
  • natas
  • Posts: 308
  • Loc: AFK

Post 3+ Months Ago

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.
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

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. }
  • alexislalas
  • Novice
  • Novice
  • alexislalas
  • Posts: 32

Post 3+ Months Ago

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
  • Posts: 6243
  • Loc: Seattle, WA

Post 3+ Months Ago

http://us2.php.net/sprintf
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

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. :)
  • alexislalas
  • Novice
  • Novice
  • alexislalas
  • Posts: 32

Post 3+ Months Ago

oh, ok, thanks to both!!

Post Information

  • Total Posts in this topic: 7 posts
  • Users browsing this forum: spork and 74 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
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.