C#のターン進

1.byte [] 16進文字列の変換

   1.1 BitConverter方法

            VAR STR = DateTime.Now.ToString()。
            VARエンコード= Encoding.UTF8。 VARバイト= encode.GetBytes(STR)。VARヘクス= BitConverter.ToString(バイト0).Replace(" - "、文字列.Empty).ToLower(); Console.WriteLineを(16進数)。

   1.2 StringBuilderの道

           VAR STR = DateTime.Now.ToString()。
            VARエンコード= Encoding.UTF8。 VARバイト= encode.GetBytes(STR)。StringBuilderのRET = 新しいStringBuilderの(); foreachの(バイトB におけるバイト){ // {0:X2}大写ret.AppendFormat(" {0:X2} " 、B)。} VARヘクス= ret.ToString()。Console.WriteLineを(16進数)。

 

2.16進文字列変換バイト[]

          VAR inputByteArray = 新しいバイト[hex.Length / 2 ]。 (のためのVAR X = ; X <inputByteArray.Length 0 X ++ ){ VAR I = Convert.ToInt32(hex.Substring(X * 2、2)、16 )。inputByteArray [X] =(バイト)I。} STR = encode.GetString(inputByteArray)。Console.WriteLineを(STR)。

おすすめ

転載: www.cnblogs.com/YZFHKMS-X/p/11740328.html