Calculates the HEX values of an array of bytes and produces a hex string
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
namespace FStore.Utils
{
/// <summary>
/// Class containing utilities used internally and available for external use
/// </summary>
public static class PublicUtils
{
/// <summary>
/// Calculates the HEX values of an array of bytes and produces a hex string
/// </summary>
/// <param name="data">The byte array to calculate the Hex values for</param>
/// <param name="hyphenate">Whether to hyphenate the Hex values</param>
/// <returns></returns>
public static string UAsHex(this byte[] data, bool hyphenate = false)
{
StringBuilder sb = new StringBuilder();
foreach (byte by in data)
{
sb.Append(by.ToString("X2"));
if (hyphenate)
sb.Append("-");
}
return sb.ToString().TrimEnd('-');
}
}
}
Related examples in the same category