Computer >> 컴퓨터 >  >> 프로그램 작성 >> C#

C# BitConverter.ToChar() 메서드

<시간/>

C#의 BitConverter.ToChar() 메서드는 바이트 배열의 지정된 위치에 있는 2바이트에서 변환된 유니코드 문자를 반환하는 데 사용됩니다.

구문

public static char ToChar (byte[] value, int begnIndex);

위에서 val은 바이트 배열이고, begnIndex는 val 내의 시작 위치입니다.

using System;
public class Demo {
   public static void Main() {
      byte[] arr = { 0, 20, 50, 65 };
      Console.WriteLine("Array = {0} ",
      BitConverter.ToString(arr));
      for (int i = 1; i < arr.Length - 1; i = i + 2) {
         char values = BitConverter.ToChar(arr, i);
         Console.WriteLine("Value = "+arr[i]);
         Console.WriteLine("Result = "+values);
      }
   }
}

출력

Array = 00-14-32-41
Value = 20
Result = ㈔

using System;
public class Demo {
   public static void Main() {
      byte[] arr = { 50, 13, 23, 18, 160 };
      Console.WriteLine("Array = {0} ",
      BitConverter.ToString(arr));
      for (int i = 1; i < arr.Length - 1; i = i + 2) {
         char values = BitConverter.ToChar(arr, i);
         Console.WriteLine("Value = "+arr[i]);
         Console.WriteLine("Result = "+values);
      }
   }
}

출력

Array = 32-0D-17-12-A0
Value = 13
Result = ᜍ
Value = 18
Result = ꀒ