java - How to represent a 5 letter string as digit? -
i want create numerical representation of 5 letter codes. codes may have 1-5 letters or digits.
the number must of course unique. not absolutely necessairy numbers can converted ascii.
thus need digits 0
zzzzz
the resulting number size should small possible.
i started following, it's not quite want:
string a="zzzzzz"; (int = 0; < a.length(); ++i) { system.out.print(a.charat(i)-'a'+1); } zzzzzz=262626262626 000000=-16-16-16-16-16-16
start enumerating possible "digits" of number:
- ten decimal digits
0
through9
- twenty 6 letters
a
throughz
you have 36 possible "digits" 5 positions, max number 365=60,466,176. number fits in int
.
you can make number calling integer.parseint
, , passing radix of 36:
system.out.println(integer.parseint("abzxy", 36)); // 17355958
Comments
Post a Comment