- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# BitConverter.ToString(Byte[]) Method
The BitConverter.ToString() method in C# is used to convert the numeric value of each element of a specified array of bytes to its equivalent hexadecimal string representation.
Syntax
public static string ToString (byte[] val);
Above, val is the byte array.
Example
using System; public class Demo { public static void Main() { byte[] arr = {0, 10, 2, 5, 32, 45}; int count = arr.Length; Console.Write("Byte Array... "); for (int i = 0; i < count; i++) { Console.Write("
"+arr[i]); } Console.WriteLine("
Byte Array (String representation) = {0} ", BitConverter.ToString(arr)); } }
Output
Byte Array... 0 10 2 5 32 45 Byte Array (String representation) = 00-0A-02-05-20-2D
Example
using System; public class Demo { public static void Main() { byte[] arr = { 0, 0, 7, 10, 18, 20, 25, 26, 32}; int count = arr.Length; Console.Write("Byte Array... "); for (int i = 0; i < count; i++) { Console.Write("
"+arr[i]); } Console.WriteLine("
Byte Array (String representation) = "+BitConverter.ToString(arr)); for (int i = 0; i < arr.Length - 1; i = i + 2) { short res = BitConverter.ToInt16(arr, i); Console.WriteLine("
Value = "+arr[i]); Console.WriteLine("Result = "+res); } } }
Output
Byte Array... 0 0 7 10 18 20 25 26 32 Byte Array (String representation) = 00-00-07-0A-12-14-19-1A-20 Value = 0 Result = 0 Value = 7 Result = 2567 Value = 18 Result = 5138 Value = 25 Result = 6681
Advertisements
To Continue Learning Please Login
Login with Google