数据按照十六进制文本输入,可自动调节输出宽度
2014-09-15 09:22
281 查看
public static string PrintHex(byte[] data, int rowLength) { if (rowLength % 2 == 1) throw new ArgumentException("必须是偶数!"); var buffer = new StringBuilder(); string segmentNumber = ""; string bytes = ""; string ascii = ""; for (int i = 1; i <= data.Length; i++) { bytes += (data[i - 1].ToString("X2")) + " "; if (data[i - 1] < 0x21 || data[i - 1] > 0x7e) { ascii += "."; } else { ascii += Encoding.ASCII.GetString(new byte[1] { data[i - 1] }); } if (i % rowLength != 0 && i % (rowLength / 2) == 0) { bytes += " "; ascii += " "; } if (i % rowLength == 0) { segmentNumber = ((((i - rowLength) / rowLength) * rowLength).ToString("X4")); buffer.AppendLine(segmentNumber + " " + bytes + " " + ascii); bytes = ""; ascii = ""; continue; } if (i == data.Length) { segmentNumber = (((((i - rowLength) / rowLength) + 1) * rowLength).ToString("X4")); buffer.AppendLine(segmentNumber + " " + bytes.PadRight(rowLength * 3 + 1, ' ') + " " + ascii); } } return buffer.ToString(); }
截图示例:
相关文章推荐
- 输入一个整数,把该整数分别按照八进制、十进制、十六进制形式输出
- 利用文本.txt输入(输出)数据--测试数据事倍功半
- 如何自动截获输出到打印机的文本数据(转载)
- 输入长整形数据输出对应的十六进制字符串
- Problem Description 有一个长度为n(n<=100)的数列,该数列定义为从2开始的递增有序偶数,现在要求你按照顺序每m个数求出一个平均值,如果最后不足m个,则以实际数量求平均值。编程输出该平均值序列。 Input 输入数据有多组,每组占一行,包含两个正整数n和m,n和m的含义
- 数据表记录包含表索引和数值,请对表索引相同的记录进行合并,即将相同索引的数值进行求和运算,输出按照key值升序进行输出。 输入描述: 先输入键值对的个数 然后输入成对的index和value值,以
- 输入一个整数,把该整数分别按照八进制、十进制、十六进制形式输出
- 输入一个整数,把该整数分别按照八进制、十进制、十六进制形式输出
- PHP 输出头像到网页,按照输入的参数自动缩放图片
- 数据挖掘之web文本自动分类
- jQuery - 综合实例 - 文本输入区域与标签自动更换
- 数据库操作_连接SQL Server数据库示例;连接ACCESS数据库;连接到 Oracle 数据库示例;SqlCommand 执行SQL命令示例;SqlDataReader 读取数据示例;使用DataAdapter填充数据到DataSet;使用DataTable存储数据库表;将数据库数据填充到 XML 文件;10 使用带输入参数的存储过程;11 使用带输入、输出参数的存储过程示;12 获得数据库中表的数目和名称;13 保存图片到SQL Server数据库示例;14 获得插入记录标识号;Exce
- 从键盘输入20个整数将奇数&偶数分别存在不同的数组中并按先奇数后偶数的顺序输出这两个数组中的数据
- 用js控制不允许输入空格和自动清楚文本中的空格
- 文本溢出超过宽度自动用省略号代替
- 用javascript判断输入数据是否货币并自动添加¥符号的代码
- MS SQL SERVER 图像或大文本的输入输出
- 自动焦点回车输入数据
- 用 Python 的输入输出功能读取和写入数据
- 怎么样在PB的数据窗口中一输入一个汉字就自动的取出它的拼音字母的第一个