This commit is contained in:
2023-01-09 00:18:00 +00:00
parent 7e912eb989
commit 92392d23e3
4 changed files with 1050 additions and 2 deletions

View File

@@ -1,4 +1,5 @@
using System;
using System.Text;
namespace Sockeye.Util
{
@@ -138,6 +139,32 @@ namespace Sockeye.Util
}
public static string ToHex(string str)
{
var sb = new StringBuilder();
var bytes = Encoding.ASCII.GetBytes(str);
foreach (var t in bytes)
{
sb.Append(t.ToString("X2"));
}
return sb.ToString(); // returns: "48656C6C6F20776F726C64" for "Hello world"
}
public static string FromHex(string hexString)
{
var bytes = new byte[hexString.Length / 2];
for (var i = 0; i < bytes.Length; i++)
{
bytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
}
return Encoding.ASCII.GetString(bytes); // returns: "Hello world" for "48656C6C6F20776F726C64"
}
}//eoc
}//eons