❔ Bytes to UInt64
I am having a issue trying to turn the hex output to ulong, (UINT64). I keep getting 6687895829614943646 from 5CD02DD2B303DD9E
I know 5CD02DD2B303DD9E should be 11447309898705915996 since my hex editor is right. I am using Little Endian.
Any help would be appreciated, thank you.
Here is my code:
I know 5CD02DD2B303DD9E should be 11447309898705915996 since my hex editor is right. I am using Little Endian.
Any help would be appreciated, thank you.
Here is my code:
private void GenerateHash()
{
// Make sure the input is not empty.
if (HashInput.Text.Length > 0)
{
// Convert \ to /
string hashInput = HashInput.Text.Replace(@"\", "/");
HashInput.Text = hashInput;
string hashString;
if (HashTypeList.SelectedIndex == 0)
{
hashString = ByteConverter.ByteArrayToString(HashFNV1.Hash(hashInput));
}
else
{
hashString = ByteConverter.ByteArrayToString(HashFNV1A.Hash(hashInput));
}
if (OutputAsHex.Checked)
{
HashResult.Text = hashString;
}
else
{
try
{
// Convert to UInt64
byte[] byteArray = HashFNV1A.Hash(hashInput);
if (BitConverter.IsLittleEndian)
Array.Reverse(byteArray);
ulong ulongValue = Convert.ToUInt64(hashString, 16);
HashResult.Text = ulongValue.ToString();
}
catch (OverflowException)
{
Console.WriteLine("Unable to convert '{0}' to an unsigned long integer.", hashString);
}
catch (FormatException)
{
Console.WriteLine("'{0}' is not in the correct format.", hashString);
}
}
}
} private void GenerateHash()
{
// Make sure the input is not empty.
if (HashInput.Text.Length > 0)
{
// Convert \ to /
string hashInput = HashInput.Text.Replace(@"\", "/");
HashInput.Text = hashInput;
string hashString;
if (HashTypeList.SelectedIndex == 0)
{
hashString = ByteConverter.ByteArrayToString(HashFNV1.Hash(hashInput));
}
else
{
hashString = ByteConverter.ByteArrayToString(HashFNV1A.Hash(hashInput));
}
if (OutputAsHex.Checked)
{
HashResult.Text = hashString;
}
else
{
try
{
// Convert to UInt64
byte[] byteArray = HashFNV1A.Hash(hashInput);
if (BitConverter.IsLittleEndian)
Array.Reverse(byteArray);
ulong ulongValue = Convert.ToUInt64(hashString, 16);
HashResult.Text = ulongValue.ToString();
}
catch (OverflowException)
{
Console.WriteLine("Unable to convert '{0}' to an unsigned long integer.", hashString);
}
catch (FormatException)
{
Console.WriteLine("'{0}' is not in the correct format.", hashString);
}
}
}
}