-Fixed build
-Removed unused code
This commit is contained in:
@@ -62,6 +62,48 @@ namespace Newtonsoft.Json.Tests
|
||||
return sw.ToString();
|
||||
}
|
||||
|
||||
protected string BytesToHex(byte[] bytes)
|
||||
{
|
||||
return BytesToHex(bytes, false);
|
||||
}
|
||||
|
||||
protected string BytesToHex(byte[] bytes, bool removeDashes)
|
||||
{
|
||||
string hex = BitConverter.ToString(bytes);
|
||||
if (removeDashes)
|
||||
hex = hex.Replace("-", "");
|
||||
|
||||
return hex;
|
||||
}
|
||||
|
||||
protected byte[] HexToBytes(string hex)
|
||||
{
|
||||
string fixedHex = hex.Replace("-", string.Empty);
|
||||
|
||||
// array to put the result in
|
||||
byte[] bytes = new byte[fixedHex.Length / 2];
|
||||
// variable to determine shift of high/low nibble
|
||||
int shift = 4;
|
||||
// offset of the current byte in the array
|
||||
int offset = 0;
|
||||
// loop the characters in the string
|
||||
foreach (char c in fixedHex)
|
||||
{
|
||||
// get character code in range 0-9, 17-22
|
||||
// the % 32 handles lower case characters
|
||||
int b = (c - '0') % 32;
|
||||
// correction for a-f
|
||||
if (b > 9) b -= 7;
|
||||
// store nibble (4 bits) in byte array
|
||||
bytes[offset] |= (byte)(b << shift);
|
||||
// toggle the shift variable between 0 and 4
|
||||
shift ^= 4;
|
||||
// move to next byte
|
||||
if (shift != 0) offset++;
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
#if !NETFX_CORE
|
||||
[SetUp]
|
||||
protected void TestSetup()
|
||||
|
||||
Reference in New Issue
Block a user