How to convert hex string to an integer in C#

3 Answers

0 votes
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                string hex = "0003FE0A";
                int n = int.Parse(hex, System.Globalization.NumberStyles.HexNumber);
                Console.WriteLine(n);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}

/*
run:
 
261642

*/


answered Mar 24, 2015 by avibootz
0 votes
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                string hex = "0003FE0A";
                int n = Convert.ToInt32(hex, 16);
                Console.WriteLine(n);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}

/*
run:
 
261642

*/


answered Mar 24, 2015 by avibootz
0 votes
using System;
using System.Globalization;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                string hex = "0003FE0A";
                int n = int.Parse(hex, NumberStyles.HexNumber);
                Console.WriteLine(n);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}

/*
run:
 
261642

*/


answered Mar 24, 2015 by avibootz

Related questions

1 answer 183 views
1 answer 267 views
1 answer 95 views
1 answer 72 views
72 views asked Nov 19, 2024 by avibootz
1 answer 103 views
2 answers 146 views
1 answer 228 views
228 views asked Mar 24, 2015 by avibootz
...