I am trying to convert a StringBuilder into an Int64 but I get Overflow Exception and I cannot figure out why. The length of the string is not greater than the int. My current code is:
+ $exception {"Value was either too large or too small for an Int64."} System.Exception {System.OverflowException}
private static Int64 EightBit(string Data)
{
StringBuilder Pile = new StringBuilder();
char[] values = Data.ToCharArray();
foreach (char letter in values)
{
// Get the integral value of the character.
int value = Convert.ToInt32(letter);
// Convert the decimal value to a hexadecimal value in string form.
string hexOutput = String.Format("{0:X}", value);
Pile.Append(Convert.ToString(Convert.ToInt32(hexOutput, 16), 2));
}
return Convert.ToInt64(Pile.ToString()); //Error here
}
Convert.ToInt64("8765432187654321")... after you have such sample you may be able to answer yourself...Converts seems overcomplicated... What I see that you are trying to createInt64from binary representation stored in strng... Maybe you forgot to add2inConvert.ToInt64(Pile.ToString(), 2)int value = Convert.ToInt32(letter);as you are using ASCII value of character, so0becomes 48, not 0.