So I think 256 comes from 2^8, and does that have to do with 8 bits integers/memories and two's complement? I am pretty bad with those. Can anyone explain to me in understandable terms? I don't get the "x=" part. Suppose we have a string:Hello.

Now, let's take "Hello" and walk through it.

i = 0: c is the int value of "H" which is 72 (see http://www.asciitable.com/). temp1 is 72. x is 72 % modulus.

i = 1: c is the int value of "e" which is 101. Assuming modulus > 72, temp1 is (101 + 256 * 72 == 18533. x is 18533 % modulus.

etc.

SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6

How To Ask Questions How To Answer Questions

On an aside, the teacher takes the size of the hash table in account. This is not really necessary, because the internals of any hash tables in Java already take care of this.

*The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.*

SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6

How To Ask Questions How To Answer Questions

Rob Spoor wrote:Let's make the code a bit more readable by splitting up that one statement, shall we?

Now, let's take "Hello" and walk through it.

i = 0: c is the int value of "H" which is 72 (see http://www.asciitable.com/). temp1 is 72. x is 72 % modulus.

i = 1: c is the int value of "e" which is 101. Assuming modulus > 72, temp1 is (101 + 256 * 72 == 18533. x is 18533 % modulus.

etc.

Hi Rob, thanks for rearranging the code! I hate the one-liners as well. I get the mechanism, but I was just wondering why x*256? My teacher mentioned something about binary numbers.