Efective way to avoid integer overflow when multiplying?
- by Jonathan
Hi, I'm working on a hash function which gets a string as input.
Right now I'm doing a loop and inside the hash (an int variable) is being multiplied by a value and then the ASCII code for the current character is added to the mix.
hash = hash * seed + string[i]
But sometimes, if the string is big enough there is an integer overflow there, what…