用uint计算

时间:2019-07-28 16:03:08

标签: c#

我有用于从字符串输入中计算uint编号的代码

当我输入类似“ X1_Lore_Realmwalker”的输入文本时给出“ 1960749072”,这是正确的数字,但是当我输入其他文本“ Lore_AzmodansOrders1”给出2909223662但该数字不正确时,应为-1385743634,但该程序未计算出正确的值< / p>

            uint HashLowerCase(string input)
            {
                input = input.ToLowerInvariant();
                uint hash = 0;
                for (int i = 0; i < input.Length; i++)
                    hash = (hash << 5) + hash + input[i];
                return hash;                

            }
            Console.WriteLine(test);
            Console.ReadKey();

1 个答案:

答案 0 :(得分:1)

uint是无符号整数,您不能使其包含负数。将所有uint更改为int(方法签名和hash变量类型)。