-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add constructor and change the constructor signature.
- Loading branch information
Showing
10 changed files
with
571 additions
and
255 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace GodSharp.Extension | ||
{ | ||
/// <summary> | ||
/// Byte extension methods class. | ||
/// </summary> | ||
public static class ByteExtension | ||
{ | ||
/// <summary> | ||
/// Bytes to hexadecimal. | ||
/// </summary> | ||
/// <param name="bytes">The byte array.</param> | ||
/// <param name="separator">The separator,default is space</param> | ||
/// <returns>String of hex.</returns> | ||
public static string ToHexString(this byte[] bytes,string separator=" ") | ||
{ | ||
if (bytes==null||bytes.Length<1) | ||
{ | ||
return null; | ||
} | ||
|
||
List<string> list = new List<string>(); | ||
foreach (byte b in bytes) | ||
{ | ||
list.Add(b.ToString("X2")); | ||
} | ||
|
||
return string.Join(separator, list.ToArray()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
|
||
namespace GodSharp.Extension | ||
{ | ||
/// <summary> | ||
/// String extension methods class. | ||
/// </summary> | ||
public static class StringExtension | ||
{ | ||
/// <summary> | ||
/// Hexadecimal string to an byte array. | ||
/// </summary> | ||
/// <param name="hex">The hex string.</param> | ||
/// <returns>An byte array.</returns> | ||
public static byte[] HexToByte(this string hex) | ||
{ | ||
// remove space | ||
hex = hex.Replace(" ", ""); | ||
|
||
byte[] bytes = new byte[hex.Length / 2]; | ||
for (int i = 0; i < hex.Length; i += 2) | ||
{ | ||
bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16); | ||
} | ||
return bytes; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.