问题描述
ffd8ffe000104a46494600010100004800480000ffe100584578696600004d4d002a000000080002011200030000000100010000876900040000000100000026000000000003a00100030000000100010000a002000400000001000008e0a003000400000001000005ec00000000ffed003850686f746f73686f7020332e30003842494d04040000000000003842494d0425000000000010d41d8cd98f00b204e9800998ecf8427effc000110805ec08e003012200021101031101ffc4001f0000010501010101010100000000000000000102030405060708090a0bffc400b51000020103030204这是一部分二进制字符串如何转换成同等的二进制格式
解决方案
解决方案二:
求大神
解决方案三:
你的意思不是split('')吗?
解决方案四:
引用2楼hanjun0612的回复:
你的意思不是split('')吗?
我的意思是我把一组二进制的字符串(string类型)转换成二进制类型(byte[])例如string类型的01010101转换成二进制也是01010101
解决方案五:
vars="ffd8ffe000104a46494600010100004800480000ffe100584578696600004d4d002a000000080002011200030000000100010000876900040000000100000026000000000003a00100030000000100010000a002000400000001000008e0a003000400000001000005ec00000000ffed003850686f746f73686f7020332e30003842494d04040000000000003842494d0425000000000010d41d8cd98f00b204e9800998ecf8427effc000110805ec08e003012200021101031101ffc4001f0000010501010101010100000000000000000102030405060708090a0bffc400b51000020103030204";vara=s.Split('').Select(x=>(int)Convert.ToInt64(x,16)).ToArray();Console.WriteLine(a[1].ToString("x8"));//00104a46验证无误
解决方案六:
哥,你这串口通信吧,按协议来,不是“把一组二进制的字符串(string类型)转换成二进制类型(byte[])”。
解决方案七:
引用4楼xuzuning的回复:
vars="ffd8ffe000104a46494600010100004800480000ffe100584578696600004d4d002a000000080002011200030000000100010000876900040000000100000026000000000003a00100030000000100010000a002000400000001000008e0a003000400000001000005ec00000000ffed003850686f746f73686f7020332e30003842494d04040000000000003842494d0425000000000010d41d8cd98f00b204e9800998ecf8427effc000110805ec08e003012200021101031101ffc4001f0000010501010101010100000000000000000102030405060708090a0bffc400b51000020103030204";vara=s.Split('').Select(x=>(int)Convert.ToInt64(x,16)).ToArray();Console.WriteLine(a[1].ToString("x8"));//00104a46验证无误
解决方案八:
namespaceConsoleApplication1{classProgram{staticvoidMain(string[]args){varstr="ffd8ffe000104a46494600010100004800480000ffe100584578696600004d4d002a000000080002011200030000000100010000876900040000000100000026000000000003a00100030000000100010000a002000400000001000008e0a003000400000001000005ec00000000ffed003850686f746f73686f7020332e30003842494d04040000000000003842494d0425000000000010d41d8cd98f00b204e9800998ecf8427effc000110805ec08e003012200021101031101ffc4001f0000010501010101010100000000000000000102030405060708090a0bffc400b51000020103030204";varbytes=HexStringToByteArray(str.Replace("",""));}publicstaticbyte[]HexStringToByteArray(StringhexString){intstart=0;if(hexString[0]=='0'&&(hexString[1]=='x'||hexString[1]=='X'))start=2;byte[]bytes=newbyte[(hexString.Length-start)/2];for(inti=start,len=hexString.Length;i<len;i+=2)bytes[i/2]=Convert.ToByte(hexString.Substring(i,2),16);returnbytes;}}}
解决方案九:
“同等的二进制格式”是什么格式?你先要给出一个靠谱的说明出来。
解决方案十:
引用2楼hanjun0612的回复:
你的意思不是split('')吗?
split之后就可能要转为List<byte[]>。不知道lz所谓的最终二进制格式什么“格式”,所以split也非重点。