There is a string

string a = "0x1234"; 

need to convert to

 int a = 0x1234 

Help me please.

    1 answer 1

    You can use the Convert.ToInt32 method with the base of the number system:

     int i = Convert.ToInt32(a, 16); 
    • In this case, i = 4660, but I need i = 0x1234 - Anastasia
    • one
      @Anastasia is the same number. In the decimal system, it is equal to 4660 , in hexadecimal - 0x1234 . - Dmitry D.
    • I know, but I need to compare it with the mask bit by bit, so I need but 0x1234 in this representation and of type int. - Anastasia
    • one
    • one
      @Anastasia To output numbers in the 16th format, specify the format "X" for it, for example: Console.WriteLine("{0:X}", i); . MSDN - Dmitry D.