ForDigit

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi I am new to C# and also new to java - though I have a reasonable knowledge of VB.Net anyway my question is this does anybody know the equivalent coded for the java forDigit(int digit,int radix) in c# as the conversion tool does not do this. It wouldn't be so bad if I knew exactly what the java code is actually meant to do exactly, as it is i am only guessing.
 
Barry said:
Hi I am new to C# and also new to java - though I have a reasonable knowledge of
VB.Net anyway my question is this does anybody know the equivalent coded for the java
forDigit(int digit,int radix) in c# as the conversion tool does not do this. It wouldn't be so
bad if I knew exactly what the java code is actually meant to do exactly, as it is i am only
guessing.


I don't know Java, but just looking at the docs you probably want something
like this:

class Character
{
public const int MIN_RADIX = 2;
public const int MAX_RADIX = 36;

public static char forDigit(int digit, int radix)
{
if (radix < MIN_RADIX || radix > MAX_RADIX)
throw new ArgumentOutOfRangeException("radix");

if (digit < 0 || digit >= radix)
throw new ArgumentOutOfRangeException("digit");

if (digit < 10)
return (char) (digit + (int) '0');

return (char) (digit - 10 + (int) 'a');
}
}
 
Back
Top