1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

データを16進ダンプする

Posted at

前提

  • C# 6
  • staticクラス内で定義しない(拡張メソッドにしない)場合は、第1引数のthisを取ってください。

できること

  • byte配列を渡すと、16進ダンプした文字列を返します。

コード

/// <summary>データを16進ダンプする</summary>
public static string Dump (this byte [] data, int width = 16, string separator = " ") {
	var str = new List<string> { };
	for (var i = 0; i < data.Length; i++) {
		str.Add ($"{((i <= 0) ? "" : ((width > 0 && i % width == 0) ? "\n" : separator))}{data [i].ToString ("X2")}");
	}
	return str.Join ("");
}

使い方

byte [] data;
// ~
Debug.Log (data.Dump ());
  • width0を渡すと、折り返しません。
1
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?