/// <summary> /// Returns the hexadecimal representation (upper-case) of the given byte array. /// </summary> /// /// <param name="buffer"> /// The byte array to format. /// </param> /// <param name="delimiter"> /// The delimiter to be used. /// </param> /// /// <returns> /// A string representation of the given byte array. /// </returns> /// /// <exception cref="ArgumentNullException"> /// Null values are invalid. /// </exception> public static String ToHex(this Byte[] buffer, String delimiter) { Verify.NotNull(buffer, nameof(buffer)); Verify.NotNull(delimiter, nameof(delimiter)); return(HexFormatter.ToUpper(buffer, 0, buffer.Length, delimiter)); }
public void Format_Byte_ToUpper() { Check.That(HexFormatter.ToUpper(0x00)).IsEqualTo("00"); Check.That(HexFormatter.ToUpper(0x01)).IsEqualTo("01"); Check.That(HexFormatter.ToUpper(0x10)).IsEqualTo("10"); Check.That(HexFormatter.ToUpper(0xAB)).IsEqualTo("AB"); Check.That(HexFormatter.ToUpper(0xFF)).IsEqualTo("FF"); }
/// <summary> /// Returns the upper-case hexadecimal representation of the given value. /// </summary> /// /// <param name="value"> /// The byte value to format. /// </param> /// /// <returns> /// A string representation of the given value, for example, "A7" or "F0". /// </returns> public static String ToUpperHex(this Byte value) { return(HexFormatter.ToUpper(value)); }
/// <summary> /// Returns the upper-case hexadecimal representation of the given byte array. /// </summary> /// /// <param name="buffer"> /// The byte array to format. /// </param> /// <param name="offset"> /// The byte offset in buffer where the data begin. /// </param> /// <param name="count"> /// The number of bytes. /// </param> /// <param name="delimiter"> /// The delimiter to be used. /// </param> /// /// <returns> /// A string representation of the given byte array. /// </returns> /// /// <exception cref="ArgumentNullException"> /// Null values are invalid. /// </exception> /// <exception cref="ArgumentOutOfRangeException"> /// Negative values are invalid. /// </exception> /// <exception cref="ArgumentExceedsUpperLimitException"> /// Values exceeding the inclusive upper limit are invalid. /// </exception> public static String ToUpperHex(this Byte[] buffer, Int32 offset, Int32 count, String delimiter) { Verify.ArraySegment(buffer, offset, count); return(HexFormatter.ToUpper(buffer, offset, count, delimiter)); }
public void Format_Array_ToUpper() { Check.That(HexFormatter.ToUpper(new Byte[] { }, 0, 0, "-")).IsEqualTo(String.Empty); Check.That(HexFormatter.ToUpper(new Byte[] { 0x11 }, 0, 0, "-")).IsEqualTo(String.Empty); Check.That(HexFormatter.ToUpper(new Byte[] { 0x11 }, 0, 1, "-")).IsEqualTo("11"); Check.That(HexFormatter.ToUpper(new Byte[] { 0x11, 0x22, 0x33 }, 0, 1, "-")).IsEqualTo("11"); Check.That(HexFormatter.ToUpper(new Byte[] { 0x11, 0x22, 0x33 }, 1, 1, "-")).IsEqualTo("22"); Check.That(HexFormatter.ToUpper(new Byte[] { 0x11, 0x22, 0x33 }, 1, 2, "-")).IsEqualTo("22-33"); Check.That(HexFormatter.ToUpper(new Byte[] { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 }, 0, 7, "-")) .IsEqualTo("11-22-33-44-55-66-77"); Check.That(HexFormatter.ToUpper(new Byte[] { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88 }, 0, 8, "-")) .IsEqualTo("11-22-33-44-55-66-77-88"); Check.That( HexFormatter.ToUpper( new Byte[] { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x11, 0x22, 0x33, }, 0, 9, "-" ) ) .IsEqualTo("11-22-33-44-55-66-77-88--99"); Check.That( HexFormatter.ToUpper( new Byte[] { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x11, 0x22, 0x33, }, 0, 15, "-" ) ) .IsEqualTo("11-22-33-44-55-66-77-88--99-AA-BB-CC-DD-EE-FF"); Check.That( HexFormatter.ToUpper( new Byte[] { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x11, 0x22, 0x33, }, 0, 15, " " ) ) .IsEqualTo("11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF"); Check.That( HexFormatter.ToUpper( new Byte[] { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x11, 0x22, 0x33, }, 0, 16, "-" ) ) .IsEqualTo("11-22-33-44-55-66-77-88--99-AA-BB-CC-DD-EE-FF-11"); Check.That( HexFormatter.ToUpper( new Byte[] { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x11, 0x22, 0x33, }, 0, 17, "-" ) ) .IsEqualTo("11-22-33-44-55-66-77-88--99-AA-BB-CC-DD-EE-FF-11--22"); Check.That( HexFormatter.ToUpper( new Byte[] { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x11, 0x22, 0x33, }, 0, 17, ":" ) ) .IsEqualTo("11:22:33:44:55:66:77:88::99:AA:BB:CC:DD:EE:FF:11::22"); Check.That( HexFormatter.ToUpper( new Byte[] { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x11, 0x22, 0x33, }, 0, 17, String.Empty ) ) .IsEqualTo("112233445566778899AABBCCDDEEFF1122"); Check.That( HexFormatter.ToUpper( new Byte[] { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x11, 0x22, 0x33, }, 7, 10, "-" ) ) .IsEqualTo("88-99-AA-BB-CC-DD-EE-FF--11-22"); }