0

I am trying to port some code from java to C#, I have faced 2 problems so far. Here is the Java code:

public static void main(String[] args)
{
    var ia = new byte[args.length];

    for (int i = 0; i < args.length; i++)
        try
        {
            ia[i] = Integer.decode(args[i]).byteValue();
        }
        catch (NumberFormatException e)
        {
        }
    System.out.
    println(Integer.toHexString(Calc(ia, ia.length)));
}

Obviously I have to change main to Main, length to Length but no idea about:

Integer.decode(args[i]).byteValue()

and

Integer.toHexString(Calc(ia, ia.length)).

Can someone tell me please what are the avilable options in .NET in these cases?!

3
  • if you're specifically trying to convert from hex values in string format to integer (and backwards), you may want to check this article on the MSDN Commented Oct 4, 2012 at 10:27
  • what do Calc means in your code? Commented Oct 4, 2012 at 10:33
  • Look at the API documentation of class Integer to find out what the decode and toHexString methods do. Commented Oct 4, 2012 at 12:54

2 Answers 2

1

Possible conversion code from java to c#.Net:

public static void Main(string[] args)
{
     var ia = new byte[args.Length];

     for (int i = 0; i < args.Length; i++)
     try
     {
        ia[i] = Convert.ToByte(args[i]);
     }
     catch (FormatException e)
     {
     }
   System.Console.WriteLine(String.Format("{0:X}",Calc(ia, ia.Length))); /// I assume Calc is function return something
}
Sign up to request clarification or add additional context in comments.

Comments

0

You can use Convert.toInt32(string) or Parse.Int32(string)

1 Comment

Should I use this for both Integer.decode and Integer.toHexString ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.