I have an HTTP connector in my iPhone project, and using a phoner-no-loop in the query, Should be set (FNV) hash
I have a Java implementation that is currently working, this code is:
long fnv_prime = 0x811C9DC5; Long hash = 0; For (int i = 0; i & lt; str.length (); i ++) {hash * = fnv_prime; Hash ^ = str.charAt (i); }
Now on the iPhone, I did this:
int64_t fnv_prime = 0x811C9DC5; Int64_T hash = 0; For (int i = 0; i & lt; [myString length]; i ++) {hash * = fnv_prime; Hash ^ = [MyStreamColorItindex: I]; }
This script does not give me a single result. Is one of java.
In the first loop, I get this:
hash = 0
hash = 100 (the first letter is "D")
Hash = 1865261300 (like java for hash = 100 and fnv_prime = -2128831035)
Is anyone missing me something?
Thanks in advance for help!
In Java, this line:
long fnv_prime = 0x811C9DC5;
will generate the fnv_prime
in the numeric value -2128831035, because continuous is interpreted as int
, which is 32-bit The value signed in Java is increased if the value is written in long
.
In contrast, the purpose-in the C code:
int64_t fnv_prime = 0x811C9DC5; 0x811C9DC5
is defined as a unsigned int
static (since it fits in signed 32-bit int Is not
), with numeric value 2166136261. That value is then written in fnv_prime
, and there is no indication to expand it, as far as the C compiler is concerned, the value is positive. / P>
This way you end up with different values for fnv_prime
, which show your specific results.
This is the " L
" suffix in Java, like this:
long fnv_prime = 0x811C9DC5L;
that forces the Java compiler to interpret continuously as long
, with the same numerical value that you get from Objective-C code .
Comments
Post a Comment