public void test() { //var b3 = 0x53A1; //string bstr = "101001110100001"; //var b2 = Convert.ToInt32(bstr, 2); //BitConverter.GetBytes(0b10010110); int value1 = 0b111111110100100; int value2 = 0b1101001110110110; //var value3 = Convert.ToString((value1 | value2), 2); //var value4 = Convert.ToString((value1 & value2), 2); var value5 = Convert.ToString((value1 ^ value2), 2); var oo = CRC16.GetCRC16(BitConverter.GetBytes((ushort)0xD3B6)); var oo3 = DataConvert.ByteArrayToString(oo); var oo4 = GetCRC16_2(BitConverter.GetBytes((ushort)0xD3B6), 0x8005); var oo5 = DataConvert.ByteArrayToString(oo4); CalcOnCrc16 crc16 = new CalcOnCrc16(); var crc1 = crc16.CalcNoemalCrc16(BitConverter.GetBytes((ushort)0xD3B6), 0x8005, 0xFFFF); var crcSring1 = DataConvert.ByteArrayToString(BitConverter.GetBytes(crc1)); var crc2 = crc16.CalcReversedCrc16(BitConverter.GetBytes((ushort)0xD3B6), 0xA001, 0xFFFF); var crcSring2 = DataConvert.ByteArrayToString(BitConverter.GetBytes(crc2)); }
public void test() { var str = "0300 00 1D"; //var b = str.Split(" ").Select(t => Convert.ToByte(t, 16)).ToArray(); var aa = DataConvert.StringToByteArray(str); var aa2 = DataConvert.StringToByteArray(str, false); var bb = DataConvert.ByteArrayToString(aa); var bb2 = BitConverter.GetBytes(258); //"3A 30 31 30 31 30 31 30 31 46 43 0D 0A"; var c1 = string.Join(" ", LRC.GetLRC(DataConvert.StringToByteArray("3A 30 31 30 31 30 31 30 31")).Select(t => t.ToString("X2"))); var c2 = string.Join(" ", LRC.GetLRC(DataConvert.StringToByteArray("30 31 30 31 30 31 30 31")).Select(t => t.ToString("X2"))); var c3 = string.Join(" ", LRC.GetLRC(DataConvert.StringToByteArray("30 31 30 31 30 31")).Select(t => t.ToString("X2"))); var c4 = string.Join(" ", Encoding.ASCII.GetBytes("3031").Select(t => t.ToString("X2"))); List <string> sb = new List <string>(); foreach (var item in "3A 30 31 30 31 30 30 30 31 30 30 30 31 46 43".Split(" ")) { sb.Add(((char)(Convert.ToByte(item, 16))).ToString()); } string.Join(" ", sb); var c7 = LRC.GetLRC(DataConvert.StringToByteArray("01 01 00 01 00 01")); var c5 = DataConvert.AsciiStringToByteArray("30 31 30 31 30 30 30 31 30 30 30 31 46 43"); var c6 = DataConvert.AsciiStringToByteArray("30 31 30 31 30 30 30 31 30 30 30 31 46 43", true); }
private void but_crc16calculate_Click(object sender, EventArgs e) { var byteArry = DataConvert.StringToByteArray(txt_crcstr.Text?.Trim(), false); var crc16 = CRC16.GetCRC16(byteArry); AppendText($"CRC16计算结果:{DataConvert.ByteArrayToString(crc16)}"); }
public void test() { var str = "03 00 00 1D 02 F0 80 32 03 00 00 00 01 00 02 00 1F 00 00 04 01 FF 04 00 04 00 00 00 00"; //var b = str.Split(" ").Select(t => Convert.ToByte(t, 16)).ToArray(); var aa = DataConvert.StringToByteArray(str); var bb = DataConvert.ByteArrayToString(aa); var bb2 = BitConverter.GetBytes(258); }
public void test() { var str = "0300 00 1D"; //var b = str.Split(" ").Select(t => Convert.ToByte(t, 16)).ToArray(); var aa = DataConvert.StringToByteArray(str); var aa2 = DataConvert.StringToByteArray(str, false); var bb = DataConvert.ByteArrayToString(aa); var bb2 = BitConverter.GetBytes(258); }
private void but_crc16calculate_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(txt_crcstr.Text) || txt_crcstr.Text.Trim().Replace(" ", "").Length % 2 != 0) { MessageBox.Show("请传入有效的参数"); return; } var byteArry = DataConvert.StringToByteArray(txt_crcstr.Text?.Trim(), false); var crc16 = CRC16.GetCRC16(byteArry); AppendText($"CRC16计算结果:{DataConvert.ByteArrayToString(crc16)}"); }