-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
403 additions
and
210 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
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,35 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.Linq; | ||
using JetBrains.Annotations; | ||
|
||
namespace NFirmware | ||
{ | ||
internal static class StringExtensions | ||
{ | ||
internal static long HexStringToLong([NotNull] this string hexNumber) | ||
{ | ||
if (string.IsNullOrEmpty(hexNumber)) throw new ArgumentNullException("hexNumber"); | ||
return long.Parse(PrepairHexString(hexNumber), NumberStyles.AllowHexSpecifier); | ||
} | ||
|
||
internal static byte HexStringToByte([NotNull] this string hexNumber) | ||
{ | ||
if (string.IsNullOrEmpty(hexNumber)) throw new ArgumentNullException("hexNumber"); | ||
return byte.Parse(PrepairHexString(hexNumber), NumberStyles.AllowHexSpecifier); | ||
} | ||
|
||
internal static byte[] HexStringToByteArray([NotNull] this string hexNumbers) | ||
{ | ||
if (hexNumbers == null) throw new ArgumentNullException("hexNumbers"); | ||
|
||
var numbers = hexNumbers.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); | ||
return numbers.Select(x => x.HexStringToByte()).ToArray(); | ||
} | ||
|
||
private static string PrepairHexString(string hexNumber) | ||
{ | ||
return hexNumber.StartsWith("0x") ? hexNumber.Substring(2) : hexNumber; | ||
} | ||
} | ||
} |
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.