note 104400 deleted from function.base-convert by danbrown

From: Date: Mon, 13 Jun 2011 19:22:36 +0000
Subject: note 104400 deleted from function.base-convert by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-180493@lists.php.net to get a copy of this message
Note Submitter: abecfive at gmail dot com ---- Comparing the functions Tamas and Theriault posted for converting a number to an uppercase alphabet string I found my solution is MUCH faster for real world use (at least when converting numbers for Microsoft Excel purposes). Excel 2007 has a maximum of 16,384 columns. Older versions of Excel have a max of 255 columns as previously mentioned. Converting the last column possible (16,384) I consistently get execution times ~0.0018 seconds compared to ~1.5-2.0 seconds with their functions. The execution times even out somewhere around 19 million and their functions begin to be faster. If you're doing a lot of conversions for numbers less than 19 million, my function will save loads of time. <?php function num2alpha($num) { $letter = 'A'; for($i=1; $i<=$num; $i++) { ++$letter; } return $letter; } ?> Tested on PHP 5.2.x, WinXP, Intel C2D 2.9ghz, 2gb RAM (results will vary with hardware)

« previous php.notes (#180493) next »