Byte Array To Hex String - CSharp System

CSharp examples for System:Byte Array

Description

Byte Array To Hex String

Demo Code


using System;/*  w w  w . jav  a 2s. c o m*/

public class Main{
        // taken from http://stackoverflow.com/questions/311165/how-do-you-convert-byte-array-to-hexadecimal-string-and-vice-versa/14333437#14333437
      public static string ByteArrayToHexString(byte[] bytes)
      {
         char[] c = new char[bytes.Length * 2];
         int b;
         for (int i = 0; i < bytes.Length; i++) {
            b = bytes[i] >> 4;
            c[i * 2] = (char)(55 + b + (((b-10)>>31)&-7));
            b = bytes[i] & 0xF;
            c[i * 2 + 1] = (char)(55 + b + (((b-10)>>31)&-7));
         }
         return new string(c);
      }
}

Related Tutorials