Programming/WPF [WPF string] string의 ascii, hex, dec 값 치환 + Convert 예외처리 푸어맨 2017. 6. 15. 16:28 //// ASCII, HEX, DEC 치환 함수 //// private string HexToAscii(string hex) { string ascii = ""; hex = hex.Replace(" ", ""); if (hex.Length % 2 != 0) { hex = "0" + hex; } int idx = 0, value = 0; for (idx = 0; idx < hex.Length; idx+=2) { string hexValuesSplit = hex.Substring(idx, 2); try { value = Convert.ToInt32(hexValuesSplit, 16); } catch { value = 0; } char charValue = (char)value; ascii += charValue; } return ascii; } private string HexToDec(string hex) { string dec = ""; hex = hex.Replace(" ", ""); if (hex.Length % 2 != 0) { hex = "0" + hex; } int idx = 0, value = 0; for (idx = 0; idx < hex.Length; idx += 2) { string hexValuesSplit = hex.Substring(idx, 2); try { value = Convert.ToInt32(hexValuesSplit, 16); } catch { value = 0; } dec += value; } return dec; }