2012-03-22 2 views

답변

2
string hexValues = "48 65 6C 6C 6F 20 57 6F 72 6C 64 21"; 
string[] hexValuesSplit = hexValues.Split(' '); 
foreach (String hex in hexValuesSplit) 
{ 
    // Convert the number expressed in base-16 to an integer. 
    int value = Convert.ToInt32(hex, 16); 
    // Get the character corresponding to the integral value. 
    string stringValue = Char.ConvertFromUtf32(value); 
    char charValue = (char)value; 
    Console.WriteLine("hexadecimal value = {0}, int value = {1}, char value = {2} or {3}", 
        hex, value, stringValue, charValue); 
} 

: 문자열의 16 진수 값은의 표현이다 http://msdn.microsoft.com/en-us/library/bb311038.aspx

4
int i = Convert.ToInt32("0x31", 16); 
Console.WriteLine("0x" + i.ToString("X2")) 
1

값. 실제 문자열 값은 원하는대로 변환 할 수 있습니다 (float, int 등) the conversion하는 방법에는 여러 가지가 있습니다. 간단한 예 :

// convert to int from base 16 
int value = Convert.ToInt32(hex, 16); 
1

먼저 정리하기 : 문자열은 16 진수 형식으로되어 당신이 값으로 변환 할 때 그것은 16 진수 아니라, 단지 숫자 값입니다.

사용 NumberStyle.HexNumber 지정자와 Int32.Parse 방법 : 헥스 값의 단지 표현입니다

string input = "0x31"; 

int n; 
if (input.StartsWith("0x")) { 
    n = Int32.Parse(input.Substring(2), NumberStyles.HexNumber); 
} else { 
    n = Int32.Parse(input); 
} 
1

주 - 그렇게 - 그래서 당신이 정말 요구하는 것은 당신이 문자열에서 값을 구문 분석 할 수있는 방법입니다 like :

int val = int.Parse("0x31", NumberStyles.HexNumber); 

val에 16 진수 값 0x31의 int가 있습니다.

관련 문제