Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
C# BitConverter.ToChar() Method
The BitConverter.ToChar() method in C# is used to returns a Unicode character converted from two bytes at a specified position in a byte array.
Syntax
public static char ToChar (byte[] value, int begnIndex);
Above, val is the byte array, whereas begnIndex is the beginning position within val.
Example
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);
}
}
}
Output
Array = 00-14-32-41 Value = 20 Result = ?
Example
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);
}
}
}
Output
Array = 32-0D-17-12-A0 Value = 13 Result = ? Value = 18 Result = ?
Advertisements
