Trying to put FNV64 converter from C# to Python, but stuck when multiplying ulong/int

  Kiến thức lập trình

I am trying to put code from C# to Python. I multiply long numbers with ulong in C# and it gives me not same result as in python. Python probably give me straight result, but in C# it’s different

Here is example on C#

ulong a = 14695981039346656037;
ulong b = 1099511628211;
ulong c = a * b;

Result is c = 12638153115695167455

If I do same on Python, it gives me different results

a = 14695981039346656037
b = 1099511628211
c = a * b

Result is

c  = 16158402040730025834900042659807

I don’t understand why it’s different, but if it’s possible to get on python same result? Is this something because of ulong?

I even don’t know how to search for solution.

I need this results because I am trying to make code below, that makes FNV64 hash, from C# on Python

        string path = string.Format("{0}\{1}", locale, e);
        ulong basis = 14695981039346656037;
        ulong prime = 1099511628211;

        byte[] byteData = Encoding.ASCII.GetBytes(path);
        ulong hash = basis;
        foreach (byte b in byteData)
        {
            hash *= prime;
            hash ^= b;
        }
``

LEAVE A COMMENT