C# VB 10진수 16진수 간 변환
int d=10;
d.ToString("x") // x X,,, 16 .
int x=Convert.ToInt32(d.ToString("x"),16);// 16 10 .
방법2:
static void Main()
{
int i = 446;
string hex = i.ToString( "X" /* or x * );
Console.WriteLine( hex );
int j = HexToInt( hex );
Console.WriteLine( j );
}
static int HexToInt(string hex)
{
hex = Regex.Replace(hex, "^0x", "", RegexOptions.IgnoreCase);
if (Regex.IsMatch(hex, "[g-z]", RegexOptions.IgnoreCase))
{
throw new Exception("Invalid Hexadecimal Expression.: 0x" + hex);
}
char[] chars = hex.ToUpper().ToCharArray();
Array.Reverse(chars);
int dec = 0;
for (int i = 0; i < chars.Length; i++)
{
dec += HexMapping(chars[i]) * (int)Math.Pow(16, i);
}
return dec;
}
static int HexMapping(char c)
{
switch (c)
{
case '0':
return 0;
case '1':
return 1;
case '2':
return 2;
case '3':
return 3;
case '4':
return 4;
case '5':
return 5;
case '6':
return 6;
case '7':
return 7;
case '8':
return 8;
case '9':
return 9;
case 'A':
return 10;
case 'B':
return 11;
case 'C':
return 12;
case 'D':
return 13;
case 'E':
return 14;
case 'F':
return 15;
default :
throw new Exception("Invalid Hexadecimal Character :" + c.ToString());
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.