代码:
while (stream8_12.Position < stream8_12.Length)//126 { var yyyy_08HTemp = Convert.ToString(stream8_12.ReadByte(), 16); var MM_08HTemp = Convert.ToString(stream8_12.ReadByte(), 16); var dd_08HTemp = Convert.ToString(stream8_12.ReadByte(), 16); var hh_08HTemp = Convert.ToString(stream8_12.ReadByte(), 16); var mm_08HTemp = Convert.ToString(stream8_12.ReadByte(), 16); var ss_08HTemp = Convert.ToString(stream8_12.ReadByte(), 16); var sd = Convert.ToString(stream8_12.ReadByte(), 16); var zt =Convert.ToString(stream8_12.ReadByte(), 2).PadLeft(8, '0'); DataRow tempSix = resultDtListSix_12.NewRow(); tempSix[0] = "20" + statr_yyyy_08H + "-" + statr_MM_08H + "-" + statr_dd_08H + ":" + statr_hh_08H + ":" + statr_mm_08H + ":" + statr_ss_08H; tempSix[1] = sd; for (int ss = 0; ss < zt.Length; ss++) { tempSix[ss + 2] = zt[ss].ToString() == "0" ? "是" : "否"; } }
stream8_12 是流
规则
即这样的规则:
1 2 3 4 5 6 ~~~~~~~~~~~~~~~~~~126
127 128 129 130 131 132 ~~~~~~~252
253 254 255 256 257 258 259~~~~~~ 504
循环的时候 前面6个只循环一次
你想问啥问题?
确实问题没描述清楚! 就这么说吧
1 2 3 4 5 6 ~~~~~~~~~~~~~~~~~~126
127 128 129 130 131 132 ~~~~~~~252
253 254 255 256 257 258 259~~~~~~ 504
你对着代码看这个 1 2 3 4 5 6 代表时间 位 这个只循环一次 在126这个循环里
同样 在252 里面127 128 129 130 131 132 循环一次
@s_p: 然后呢?
@Launcher: 我写了下 按自己的想法 我也描述不清楚问题 文字描述有点困难
这个是我修改的
if (dataList_8H.Rows.Count > 0) { var tempByte = (byte[])dataList_8H.Rows[0]["DP_RecvParamValue"]; stream8_12 = new MemoryStream(); byte[] tempByteList = new byte[tempByte.Length]; stream8_12.Write(tempByteList, 0, tempByte.Length); stream8_12.Position = 0; var statr_yyyy_08H = Convert.ToString(stream8_12.ReadByte(), 16); var statr_MM_08H = Convert.ToString(stream8_12.ReadByte(), 16).PadLeft(2, '0'); var statr_dd_08H = Convert.ToString(stream8_12.ReadByte(), 16).PadLeft(2, '0'); var statr_hh_08H = Convert.ToString(stream8_12.ReadByte(), 16).PadLeft(2, '0'); var statr_mm_08H = Convert.ToString(stream8_12.ReadByte(), 16).PadLeft(2, '0'); var statr_ss_08H = Convert.ToString(stream8_12.ReadByte(), 16).PadLeft(2, '0'); var end_yyyy_08H = Convert.ToString(stream8_12.ReadByte(), 16); var end_MM_08H = Convert.ToString(stream8_12.ReadByte(), 16).PadLeft(2, '0'); var end_dd_08H = Convert.ToString(stream8_12.ReadByte(), 16).PadLeft(2, '0'); var end_hh_08H = Convert.ToString(stream8_12.ReadByte(), 16).PadLeft(2, '0'); var end_mm_08H = Convert.ToString(stream8_12.ReadByte(), 16).PadLeft(2, '0'); var end_ss_08H = Convert.ToString(stream8_12.ReadByte(), 16).PadLeft(2, '0'); var count_8HTemp = readStream(stream8_12, 4); var count_8H = byteToHexStr(count_8HTemp); stream8_12.Position = 15; if (int.Parse(count_8H) * 126 != stream8_12.Length - 17) { dtAssignment(null); return; } long tempIndex = 1; while (stream8_12.Position < stream8_12.Length)//126 { var yyyy_08HTemp = Convert.ToString(stream8_12.ReadByte(), 16); var MM_08HTemp = Convert.ToString(stream8_12.ReadByte(), 16); var dd_08HTemp = Convert.ToString(stream8_12.ReadByte(), 16); var hh_08HTemp = Convert.ToString(stream8_12.ReadByte(), 16); var mm_08HTemp = Convert.ToString(stream8_12.ReadByte(), 16); var ss_08HTemp = Convert.ToString(stream8_12.ReadByte(), 16); for (long k = stream8_12.Position; k < tempIndex * 126; k++) { var sd = Convert.ToString(stream8_12.ReadByte(), 16); var zt = Convert.ToString(stream8_12.ReadByte(), 2).PadLeft(8, '0'); DataRow tempSix = resultDtListSix_12.NewRow(); tempSix[0] = "20" + statr_yyyy_08H + "-" + statr_MM_08H + "-" + statr_dd_08H + ":" + statr_hh_08H + ":" + statr_mm_08H + ":" + statr_ss_08H; tempSix[1] = sd; for (int ss = 0; ss < zt.Length; ss++) { tempSix[ss + 2] = zt[ss].ToString() == "0" ? "是" : "否"; } } tempIndex++; if (tempIndex >long.Parse( count_8H)) { break; } } dtAssignment(resultDtListEight_12); stream8_12.Close(); }
@s_p: 来学习下如何描述文件结构:http://blog.csdn.net/chun_hua/article/details/6053035