public string DataToBitString(int offset, int size, string separator = "") { var raw_data = Data; if (raw_data == null) { return(""); } return(HexTextEncoder.ToBitText(raw_data, offset, size, separator)); }
public string DataToBitString(string separator = "") { var raw_data = Data; if (raw_data == null) { return(""); } return(HexTextEncoder.ToBitText(raw_data, 0, raw_data.Length, separator)); }
public string GetFormatString(string pattern) { var blocks = pattern.Split(':'); /* 引数取得 */ var format = "HEXTEXT"; var type = "BYTE"; var offset = 0; var size = int.MaxValue; if ((blocks.Length > (int)FormatArgument.Format) && (blocks[(int)FormatArgument.Format].Length > 0)) { format = blocks[(int)FormatArgument.Format]; } if ((blocks.Length > (int)FormatArgument.Type) && (blocks[(int)FormatArgument.Type].Length > 0)) { type = blocks[(int)FormatArgument.Type]; } if ((blocks.Length > (int)FormatArgument.Offset) && (blocks[(int)FormatArgument.Offset].Length > 0)) { try { offset = int.Parse(blocks[(int)FormatArgument.Offset]); } catch {} } if ((blocks.Length > (int)FormatArgument.Size) && (blocks[(int)FormatArgument.Size].Length > 0)) { try { size = int.Parse(blocks[(int)FormatArgument.Size]); } catch {} } /* データ取得 */ var data = (byte[])null; switch (type.ToUpper()) { case "BYTE": data = GetBytes(offset, size); break; case "BIT": data = GetBits(offset, size); break; case "ASCII": data = TextToData(Encoding.ASCII, offset, size); break; case "UTF8": data = TextToData(Encoding.UTF8, offset, size); break; case "UTF16BE": data = TextToData(Encoding.BigEndianUnicode, offset, size); break; case "UTF16LE": data = TextToData(Encoding.Unicode, offset, size); break; case "SHIFTJIS": data = TextToData(Encoding.GetEncoding(932), offset, size); break; case "EUCJP": data = TextToData(Encoding.GetEncoding(20932), offset, size); break; default: return(pattern); } /* データ変換 */ var result = ""; switch (format.ToUpper()) { case "HEXTEXT": result = HexTextEncoder.ToHexText(data); break; case "BITTEXT": result = HexTextEncoder.ToBitText(data); break; case "ASCII": result = Encoding.UTF8.GetString(data); break; case "UTF8": result = Encoding.UTF8.GetString(data); break; case "UTF16BE": result = Encoding.BigEndianUnicode.GetString(data); break; case "UTF16LE": result = Encoding.Unicode.GetString(data); break; case "SHIFTJIS": result = Encoding.GetEncoding(932).GetString(data); break; case "EUCJP": result = Encoding.GetEncoding(20932).GetString(data); break; case "INT8": result = StructEncoder.ToSByte(data).ToString(); break; case "UINT8": result = StructEncoder.ToByte(data).ToString(); break; case "INT16LE": result = StructEncoder.ToInt16(data, true).ToString(); break; case "INT32LE": result = StructEncoder.ToInt32(data, true).ToString(); break; case "INT64LE": result = StructEncoder.ToInt64(data, true).ToString(); break; case "UINT16LE": result = StructEncoder.ToUInt16(data, true).ToString(); break; case "UINT32LE": result = StructEncoder.ToUInt32(data, true).ToString(); break; case "UINT64LE": result = StructEncoder.ToUInt64(data, true).ToString(); break; case "INT16BE": result = StructEncoder.ToInt16(data, false).ToString(); break; case "INT32BE": result = StructEncoder.ToInt32(data, false).ToString(); break; case "INT64BE": result = StructEncoder.ToInt64(data, false).ToString(); break; case "UINT16BE": result = StructEncoder.ToUInt16(data, false).ToString(); break; case "UINT32BE": result = StructEncoder.ToUInt32(data, false).ToString(); break; case "UINT64BE": result = StructEncoder.ToUInt64(data, false).ToString(); break; default: return(pattern); } return(result); }