using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DVBServices { internal class Utils { /// /// Convert a string of bytes to a hex string. /// /// The string to be converted. /// The string of hex characters. public static string ConvertToHex(byte[] inputChars) { return (ConvertToHex(inputChars, inputChars.Length)); } /// /// Convert a string of bytes to a hex string. /// /// The array holding the bytes to be converted. /// The number of byte to be converted. /// The string of hex characters. public static string ConvertToHex(byte[] inputChars, int length) { return (ConvertToHex(inputChars, 0, length)); } /// /// Convert a string of bytes to a hex string. /// /// The array holding the bytes to be converted. /// The the offset to the first byte to be converted. /// The number of byte to be converted. /// The string of hex characters. public static string ConvertToHex(byte[] inputChars, int offset, int length) { char[] outputChars = new char[length * 2]; int outputIndex = 0; for (int inputIndex = 0; inputIndex < length; inputIndex++) { int hexByteLeft = inputChars[offset] >> 4; int hexByteRight = inputChars[offset] & 0x0f; outputChars[outputIndex] = getHex(hexByteLeft); outputChars[outputIndex + 1] = getHex(hexByteRight); outputIndex += 2; offset++; } return ("0x" + new string(outputChars)); } private static char getHex(int value) { if (value < 10) return ((char)('0' + value)); return ((char)('a' + (value - 10))); } } }