직렬 포트에서 문자열을 읽은 다음 몇 가지 값 (이 경우 높은 바이트와 낮은 바이트의 표현)을 구문 분석하는 코드가 있는데, 그 다음에 이들을 바꿔서 결합하여 올바른 순서로 배열합니다. 결합 된 값을 십진수 값으로 변환하고 싶습니다.문자열의 16 진수 값을 숫자로 변환하는 방법은 무엇입니까?
16 진수 표현을 문자열로 16 진수로 변환하려고 시도하는 데 어려움을 겪고 있으며 그 결과를 10 진수로 변환합니다.
코드는 여기 :
private void OutputUpdateCallbackclusterTxtBox(string data)
{
string cluster;
string attribute;
string tempvalueHighByte;
string tempvalueLowByte;
string tempvalueHighLowByte; //switched around
int temporarytemp;
if (data.Contains("T00000000:RX len 9, ep 01, clus 0x0201") == true)//find our marker in thestring
{
if (data.Contains("clus") == true)
{
int index = data.IndexOf("clus"); //if we find it find the index in the string it occurs
cluster = data.Substring(index + 5, 6); //use this index add 5 and read in 6 characters from the number to get our value
attribute = data.Substring(index + 5, 1);
cluster_TXT.Text = cluster; // post the value in the test box
}
if (data.Contains("payload") == true)
{
int index = data.IndexOf("payload"); //if we find it find the index in the string it occurs
tempvalueHighByte = data.Substring(index + 20, 2); //use this index add 20 and read in 2 characters from the number to get our value
tempvalueLowByte = data.Substring(index + 23, 2); //use this index add 23 and read in 2 characters from the number to get our value
tempvalueHighLowByte = tempvalueLowByte + tempvalueHighByte;
ConvertToHex(tempvalueHighLowByte);
temporarytemp= int.Parse(tempvalueHighLowByte);
temperatureTxt.Text = ((char)temporarytemp).ToString(); // post the value in the text box
}
가 왜 진수로 바로 변환 할 수 있습니까? 왜 "문자열로"중간 단계? – Adrian
그것의 나의 결함있는 논리, 한 번에 한 걸음 씩 작업, 확실하게 16 진수로 변환 할 필요가 없습니다. –