ID:166942 May 26 2006, 5:39 pm (Edited on May 26 2006, 7:07 pm) How would I make Jave Script's parseInt(string, base) function in to a DM proc? May 26 2006, 9:58 pm Depends, what does it do? May 26 2006, 10:08 pm You would look up text2num() in the reference. :P May 26 2006, 10:36 pm In response to Jp text2num() doesn't do base conversions though. If you want base conversion you'll have to write the algorithm yourself. A web search will turn up ways of doing it; you'll have to adapt them to DM, but that shouldn't be hard provided you understand it all. May 26 2006, 10:46 pm In response to Crispy Ah, he's looking for base conversions? The basic idea is pretty simple: Numbers can be represented as follows: n=x*b**0 + y*b**1 + z*b**2... Where x, y and z are the digits. For example, 642, in decimal, is 6*10**2 + 4*10**1 + 2*10**0. That number b (10, in this case) is the base. So converting between binary and decimal is just a matter of converting x*10**0 + y*10**1 + z*10**0... into x*2**0 + y*2**1 + z*2**2... Which isn't all that difficult. May 27 2006, 7:23 am In response to Jp Can some body please convert this to DM. ```public static int parseInt(String s, int radix) throws NumberFormatException { if (s == null) { throw new NumberFormatException("null"); } if (radix < Character.MIN_RADIX) { throw new NumberFormatException("radix " + radix + " less than Character.MIN_RADIX"); } if (radix > Character.MAX_RADIX) { throw new NumberFormatException("radix " + radix + " greater than Character.MAX_RADIX"); } int result = 0; boolean negative = false; int i = 0, max = s.length(); int limit; int multmin; int digit; if (max > 0) { if (s.charAt(0) == '-') { negative = true; limit = Integer.MIN_VALUE; i++; } else { limit = -Integer.MAX_VALUE; } multmin = limit / radix; if (i < max) { digit = Character.digit(s.charAt(i++),radix); if (digit < 0) { throw NumberFormatException.forInputString(s); } else { result = -digit; } } while (i < max) { // Accumulating negatively avoids surprises near MAX_VALUE digit = Character.digit(s.charAt(i++),radix); if (digit < 0) { throw NumberFormatException.forInputString(s); } if (result < multmin) { throw NumberFormatException.forInputString(s); } result *= radix; if (result < limit + digit) { throw NumberFormatException.forInputString(s); } result -= digit; } } else { throw NumberFormatException.forInputString(s); } if (negative) { if (i > 1) { return result; } else { /* Only got "-" */ throw NumberFormatException.forInputString(s); } } else { return -result; } } ``` May 27 2006, 7:31 am In response to Y2kEric That's almost in DM as it is! You can do it. May 27 2006, 8:11 am YMIHere has a very small but very useful library for this sort of thing. YMIHere.BaseConverter 