Read Hex using BinaryReader - CSharp System.IO

CSharp examples for System.IO:BinaryReader

Description

Read Hex using BinaryReader

Demo Code


using System.Text;
using System.IO;//from w w  w.ja v a  2  s .c  om
using System.Globalization;
using System;

public class Main{
        public static string ReadHex(this BinaryReader br, int len)
        {
            return br.ReadBytes(len).ToHex();
        }
        public static string ToHex(this byte[] array)
        {
            StringBuilder stringBuilder = new StringBuilder(array.Length * 2);
            for (int index = 0; index < array.Length; ++index)
                stringBuilder.Append(array[index].ToString("x2"));
            return stringBuilder.ToString();
        }
}

Related Tutorials