DANGER Will Robinson - DANGER
Originally Posted by
SyntaX******
Ahhh, perfectly explained. I thought that could work, and understood it worked in base*0, but my insufficient math skills told me not to waist my time trying something that might not work.
Next week I will code this into the base converter using string representations of integer values for larger decimal precision. I'll give 2^*024 on the left and 2^*024 on the right side of the decimal.
I definitely agree with your selection of digits:
$digits = "0*2*45678*abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
Its logical to most of us, but the ASCII standard F's things up jumping from 0-* to :;>=< ... I think the only real use for anything from character sets from **-255 would be for encryption purposes. I'm coming up with my own, uncrackable encryption methods so it may be very useful to me, but for everyday purposes... useless.
Thanks again for the conversion example!
After some experimentation, I found a potentially serious flaw in using the letters in the way I did for the base conversions.
The base conversion logic is OK and consistent. The problem lies in the ASCII codes used for the characters and the way the computer interprets them.
This only becomes a problem if you intend to use the computer to sort a list of numbers made in bases that use alpha characters.
The ASCII codes of the uppercase letters are greater than the ASCII codes of the corresponding lowercase letters because uppercase letters come before lowercase letters in the ASCII code spectrum and will be sorted ahead of them. This is contrary to the numerical values we apply to the characters when used for numbers rather than words.
This is not good.
Since letter case is important in this instance, it leads to a list of numbers not sorting correctly in proper order if they contain any mix of upper/lowercase letters.
There are ways around this, the simplest being to switch places with upper/lowercase letters in the allowed digits string. Then all hexadecimal numbers would ALWAYS use uppercase A-Z.
Just change
$digits = "0*2*45678*abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
to
$digits = "0*2*45678*ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
and the numerical sorting problem is solved, regardless of the base used.
It seems that uppercase following lowercase is a more logical way to do it, but it works the opposite way in ASCII and that can effect anything that involves ASCII sorting algorithms.
I just thought anyone using my particular method should know about this little glitch. It could lead to erroneous sorting problems if not taken into account in some circumstances.
Last edited by JayT; 09-03-2007 at 06:00 PM.
Oh to be free, so blissfully free, of the ravages of intelligence, there is no greater joy! - The Cweationist's Cweed
All that is necessary for evil to triumph is a good PR firm.
Very funny, Scotty. Now beam down my clothes!