Last active
February 23, 2018 23:07
-
-
Save rodelta/0c3ce89cc1a9ff9f6587a4981593c57b to your computer and use it in GitHub Desktop.
Takes a hex string of arbitrary value and turns it into a binary string. Works with hex strings that would overflow number types (e.g. EPC codes).
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
/* Creates a binary string from a arbitrary long hex string | |
Taken from https://github.com/dannyhaak/TagDataTranslation/ | |
*/ | |
private static string HexToBinary(string hex) | |
{ | |
StringBuilder binary = new StringBuilder(); | |
for (int i = 0; i < hex.Length; i++) | |
{ | |
int integer = Convert.ToInt16(hex.Substring(i, 1), 16); | |
binary.Append(Convert.ToString(integer, 2).PadLeft(4, '0')); | |
} | |
return binary.ToString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment