정수를 16진수로 변환
string.ToString() 확장 메서드를 사용하여 정수를 16진수로 변환할 수 있습니다.
Integer Value: 500 Hexadecimal Value: 1F4
16진수를 정수로 변환 -
16진수 값은 int.Parse 또는 convert.ToInt32
를 사용하여 정수로 변환할 수 있습니다.int.Parse - 숫자의 문자열 표현을 해당하는 32비트 부호 있는 정수로 변환합니다. 반환 값은 작업의 성공 여부를 나타냅니다.
Hexadecimal Value: 1F4 Integer Value: 500
Convert.ToInt32 −지정된 값을 32비트 부호 있는 정수로 변환합니다.
Hexadecimal Value: 1F4 Integer Value: 500
정수를 16진수로 변환 -
문자열 hexValue =integerValue.ToString("X");
예시
using System;
namespace DemoApplication{
public class Program{
public static void Main(){
int integerValue = 500;
Console.WriteLine($"Integer Value: {integerValue}");
string hexValue = integerValue.ToString("X");
Console.WriteLine($"Hexadecimal Value: {hexValue}");
Console.ReadLine();
}
}
} 출력
위 코드의 출력은
Integer Value: 500 Hexadecimal Value: 1F4
16진수를 정수로 변환 -
int.Parse 사용 예 -
예시
using System;
namespace DemoApplication{
public class Program{
public static void Main(){
string hexValue = "1F4";
Console.WriteLine($"Hexadecimal Value: {hexValue}");
int integerValue = int.Parse(hexValue, System.Globalization.NumberStyles.HexNumber);
Console.WriteLine($"Integer Value: {integerValue}");
Console.ReadLine();
}
}
} 출력
위 코드의 출력은
Hexadecimal Value: 1F4 Integer Value: 500
Convert.ToInt32 사용 예 -
예시
using System;
namespace DemoApplication{
public class Program{
public static void Main(){
string hexValue = "1F4";
Console.WriteLine($"Hexadecimal Value: {hexValue}");
int integerValue = Convert.ToInt32(hexValue, 16);
Console.WriteLine($"Integer Value: {integerValue}");
Console.ReadLine();
}
}
} 출력
위 코드의 출력은
Hexadecimal Value: 1F4 Integer Value: 500