LoginSignup
29
23

More than 5 years have passed since last update.

【備忘録】byte配列⇒16進数文字列へ変換

Posted at

はじめに

この手の変換ってよく忘れちゃうので、明日の自分のためにメモっとく。

環境

  • Windows7 Professional SP1
  • Microsoft Visual Studio Version 12.0.31101.00 Update 4
  • Microsoft .NET Framework Version 4.5.51209
  • Microsoft Visual C# 2013

Example

    /// <summary>
    /// 【備忘録】byte配列⇒16進数文字列へ変換
    /// </summary>
    class ByteArray01
    {
        private static byte[] b = { 0x41, 0x42, 0x43 };
        private static string s = string.Empty;

        static void Main(string[] args)
        {
            // s = "41-42-43"
            s = BitConverter.ToString(b);

            // s = "414243"
            s = BitConverter.ToString(b).Replace("-", string.Empty);

            Console.ReadKey();
        }
    }
29
23
0

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
29
23