提问
如何 10进制转16进制再转2进制
回答
static int HexString2BinString(object value, int index, int length)
{
try
{
if (int.TryParse(value.ToString(), out int intValue))
{
var hexString = intValue.ToString("X4");
string result = string.Empty;
foreach (char c in hexString)
{
int v = Convert.ToInt32(c.ToString(), 16);
int v2 = int.Parse(Convert.ToString(v, 2));
// 去掉格式串中的空格,即可去掉每个4位二进制数之间的空格,
result += string.Format("{0:d4}", v2);
}
return Convert.ToInt32(result.Substring(index, length), 2);
}
throw new Exception($"无法解析{value.ToString()}");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
throw;
}
}
标签:10,Convert,进制,16,int,ToString,result
From: https://www.cnblogs.com/wuhailong/p/18027141