Reply to Re: [PHP] String format best practice

Your name:

Reply:


Posted by Richard Lynch on 03/30/05 00:42

On Tue, March 29, 2005 1:27 pm, René Fournier said:
> I need to output a Hex value, e.g.:
>
> 686E8AF8
>
> In the following format:
>
> 68 6E 8A F8
>
> In other words, separated by spaces. Now I realize there are a million
> ways to do this, but I would like a suggestion on which you think is
> the most efficient? Incidentally, I'm starting with a decimal value
> (23602210718), so maybe sprintf would be a direct way?

sprintf and "most efficient" rarely belong in the same sentence. :-)

I believe this is going to "win" almost any efficiency test, and is
reasonably self-documenting/clear:

$dec = 23602210718;
$hex = dechex($dec);
echo implode(' ', chunk_split($hex, 2));

Note that dechex only supports numbers up to 0xFFFFFFFF

In older PHP versions, I believe the limit was lower than that. 0x7FFFFFFF
perhaps, based on the user notes.

--
Like Music?
http://l-i-e.com/artists.htm

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация