C# Convert ToInt32(String, Int32)
Description
Convert ToInt32(String, Int32)
converts the string
representation of a number in a specified base to an equivalent 32-bit signed
integer.
Syntax
Convert.ToInt32(String, Int32)
has the following syntax.
public static int ToInt32(
string value,
int fromBase
)
Parameters
Convert.ToInt32(String, Int32)
has the following parameters.
value
- A string that contains the number to convert.fromBase
- The base of the number in value, which must be 2, 8, 10, or 16.
Returns
Convert.ToInt32(String, Int32)
method returns A 32-bit signed integer that is equivalent to the number in value, or 0 (zero)
if value is null.
Example
//from w ww.j a v a 2s . c om
using System;
public class MainClass{
public static void Main(String[] argv){
long sourceNumber =123;
bool isNegative = Math.Sign(sourceNumber) == -1;
string value = Convert.ToString(sourceNumber, 16);
int targetNumber = Convert.ToInt32(value, 16);
Console.WriteLine(targetNumber);
}
}
The code above generates the following result.