2个回答
展开全部
你说的是转为byte数组吧
private static byte[] ToHexByte(string hexString)
{
hexString = hexString.Replace(" ", "");
if ((hexString.Length % 2) != 0)
hexString += " ";
byte[] returnBytes = new byte[hexString.Length / 2];
for (int i = 0; i < returnBytes.Length; i++)
returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
return returnBytes;
}
private static byte[] ToHexByte(string hexString)
{
hexString = hexString.Replace(" ", "");
if ((hexString.Length % 2) != 0)
hexString += " ";
byte[] returnBytes = new byte[hexString.Length / 2];
for (int i = 0; i < returnBytes.Length; i++)
returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
return returnBytes;
}
追问
我说的是二进制数,不是byte数组,请问该如何转化
追答
static string ToBinString(string s)
{
Func toByte = (char1) => {
if (char1 >= '0' && char1 = 'A' && char1 = 'a' && char1 toBin = (byte1) =>
string.Format("{0}{1}{2}{3}",
byte1 >> 0 & 0x1,
byte1 >> 1 & 0x1,
byte1 >> 2 & 0x1,
byte1 >> 3 & 0x1
);
string result = "";
foreach (var char1 in s)
{
var b = toByte(char1);
result += toBin(b);
}
return result;
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询