Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace Utils
- {
- public class Hex
- {
- private static char[] _HexDigits = {
- '0', '1', '2', '3', '4', '5', '6', '7',
- '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
- };
- public static string ToHexString(byte[] bytes)
- {
- int j = bytes.Length;
- char[] chars = new char[j * 2];
- for (int i = 0; i < j; i++)
- {
- int b = bytes[i];
- chars[i * 2] = _HexDigits[b >> 4];
- chars[i * 2 + 1] = _HexDigits[b & 0xF];
- }
- return new string(chars);
- }
- public static string ToHexString(string sPrefix, byte[] bytes)
- {
- int k = sPrefix.Length;
- int j = bytes.Length;
- char[] chars = new char[ k + (j * 2) ];
- sPrefix.CopyTo(0, chars, 0, k);
- for (int i = 0; i < j; i++)
- {
- int b = bytes[i];
- int c = (i * 2) + k;
- chars[c] = _HexDigits[b >> 4];
- chars[c + 1] = _HexDigits[b & 0xF];
- }
- return new string(chars);
- }
- public static string ToHexString(string sPrefix, byte[] bytes, string sSuffix)
- {
- int k = sPrefix.Length;
- int m = sSuffix.Length;
- int j = bytes.Length;
- char[] chars = new char[ k + (j * 2) + m ];
- sPrefix.CopyTo(0, chars, 0, k);
- for (int i = 0; i < j; i++)
- {
- int b = bytes[i];
- int c = (i * 2) + k;
- chars[c] = _HexDigits[b >> 4];
- chars[c + 1] = _HexDigits[b & 0xF];
- }
- sSuffix.CopyTo(0, chars, k + (j * 2), m);
- return new string(chars);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement