note 104400 added to function.base-convert

From: Date: Mon, 13 Jun 2011 19:22:01 +0000
Subject: note 104400 added to function.base-convert
Groups: php.notes 
Request: Send a blank email to php-notes+get-180492@lists.php.net to get a copy of this message
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) ---- Server IP: 69.147.83.197 Probable Submitter: 12.46.52.130 ---- Manual Page -- http://www.php.net/manual/en/function.base-convert.php Edit -- https://master.php.net/note/edit/104400 Del: integrated -- https://master.php.net/note/delete/104400/integrated Del: useless -- https://master.php.net/note/delete/104400/useless Del: bad code -- https://master.php.net/note/delete/104400/bad+code Del: spam -- https://master.php.net/note/delete/104400/spam Del: non-english -- https://master.php.net/note/delete/104400/non-english Del: in docs -- https://master.php.net/note/delete/104400/in+docs Del: other reasons-- https://master.php.net/note/delete/104400 Reject -- https://master.php.net/note/reject/104400 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#180492) next »