mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[Utilities] Null in, null out
This commit is contained in:
@@ -2152,6 +2152,12 @@ namespace SabreTools.Library.Tools
|
|||||||
/// <link>http://stackoverflow.com/questions/311165/how-do-you-convert-byte-array-to-hexadecimal-string-and-vice-versa</link>
|
/// <link>http://stackoverflow.com/questions/311165/how-do-you-convert-byte-array-to-hexadecimal-string-and-vice-versa</link>
|
||||||
public static string ByteArrayToString(byte[] bytes)
|
public static string ByteArrayToString(byte[] bytes)
|
||||||
{
|
{
|
||||||
|
// If we get null in, we send null out
|
||||||
|
if (bytes == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string hex = BitConverter.ToString(bytes);
|
string hex = BitConverter.ToString(bytes);
|
||||||
@@ -2171,6 +2177,12 @@ namespace SabreTools.Library.Tools
|
|||||||
/// <link>http://stackoverflow.com/questions/311165/how-do-you-convert-byte-array-to-hexadecimal-string-and-vice-versa</link>
|
/// <link>http://stackoverflow.com/questions/311165/how-do-you-convert-byte-array-to-hexadecimal-string-and-vice-versa</link>
|
||||||
public static byte[] StringToByteArray(string hex)
|
public static byte[] StringToByteArray(string hex)
|
||||||
{
|
{
|
||||||
|
// If we get null in, we send null out
|
||||||
|
if (hex == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
int NumberChars = hex.Length;
|
int NumberChars = hex.Length;
|
||||||
@@ -2193,6 +2205,12 @@ namespace SabreTools.Library.Tools
|
|||||||
/// <link>http://stackoverflow.com/questions/5613279/c-sharp-hex-to-ascii</link>
|
/// <link>http://stackoverflow.com/questions/5613279/c-sharp-hex-to-ascii</link>
|
||||||
public static string ConvertHexToAscii(string hexString)
|
public static string ConvertHexToAscii(string hexString)
|
||||||
{
|
{
|
||||||
|
// If we get null in, we send null out
|
||||||
|
if (hexString == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (hexString.Contains("-"))
|
if (hexString.Contains("-"))
|
||||||
{
|
{
|
||||||
hexString = hexString.Replace("-", "");
|
hexString = hexString.Replace("-", "");
|
||||||
@@ -2217,6 +2235,12 @@ namespace SabreTools.Library.Tools
|
|||||||
/// <link>http://stackoverflow.com/questions/15920741/convert-from-string-ascii-to-string-hex</link>
|
/// <link>http://stackoverflow.com/questions/15920741/convert-from-string-ascii-to-string-hex</link>
|
||||||
public static string ConvertAsciiToHex(string asciiString)
|
public static string ConvertAsciiToHex(string asciiString)
|
||||||
{
|
{
|
||||||
|
// If we get null in, we send null out
|
||||||
|
if (asciiString == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
string hexOutput = "";
|
string hexOutput = "";
|
||||||
foreach (char _eachChar in asciiString.ToCharArray())
|
foreach (char _eachChar in asciiString.ToCharArray())
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user