publicvoidBitToByte(){List<char[]> chars =newList<char[]>();char mm1 ='1';char mm2 ='1';char mm3 ='1';char mm4 ='1';char mm ='0';char[] chars0 =newchar[]{ mm1, mm2, mm3, mm4, mm, mm, mm, mm };//0-7
chars.Add(chars0);byte[] bytes =newbyte[chars.Count];byte result =0;byte current =1;for(int j =0; j < chars[0].Length; j++){if(chars[0][j]=='1'){
result += current;}
current *=2;}
bytes[0]= result;}
byte转bitarray
publicvoidtest(){byte[] bytes1 =ByteArrayToHexString(arr1);BitArray bitValues1 =newBitArray(bytes1);//0-7}//publicstaticbyte[]ByteArrayToHexString(string hexString){//将16进制秘钥转成字节数组var byteArray =newbyte[hexString.Length /2];for(var x =0; x < byteArray.Length; x++){var i = Convert.ToInt32(hexString.Substring(x *2,2),16);
byteArray[x]=(byte)i;}return byteArray;}