ByteTools

A library to convert between byte arrays and strings using hex (base 16) encoding i.e. each byte is represented by 2 hex characters. The implementation makes use of an efficient table lookup that is approx 16x faster than using System.BitConverter.


Keywords
hex, encoding, byte-array
License
MIT
Install
Install-Package ByteTools -Version 1.0.0

Documentation

ByteTools

A .Net library to convert between byte arrays and strings using hex (base 16) encoding i.e. each byte is represented by 2 hex characters.

The implementation makes use of an efficient table lookup that is approx 16x faster than using System.BitConverter:

System.BitConverter.ToString(x).Replace("-", "")

Examples in C#

To convert from hex string to byte array:

var b = HexEncoding.GetBytes("2FA5"); // returns new byte [] { 0x2f, 0xa5 }

To convert from byte array to hex string:

var s = HexEncoding.GetString(new byte[] { 0x2f, 0xa5 }); // returns "2FA5"

NuGet Package

Available from NuGet: https://www.nuget.org/packages/ByteTools

Build & Test Status

Build Status