locked
How to fix this? RRS feed

  • Question

  • I want to convert string msg to hex,but I recive this error.

    P.S. I am a noob.

    Thanks!

    static void Main(string[] args)
            {
                string output = "";
                string msg = "20 32 16f";
                string[] separators = { ",", ".", "!", "?", ";", ":", " " };
                string[] words = msg.Split(separators, StringSplitOptions.RemoveEmptyEntries);
    
                foreach (var s in words)
                {
                    var x = Int16.Parse(s);
                    string hex = System.String.Format("{0:X}",x);
                    output += hex + " ";
    
                }
                Console.WriteLine(output);
                Console.ReadLine();
            }


    Friday, June 26, 2015 6:38 PM

Answers

  • In order to parse hexadecimal values, add a flag:

    var x = Int16.Parse( s, System.Globalization.NumberStyles.AllowHexSpecifier );

    Friday, June 26, 2015 7:17 PM

All replies