I have to turn this formula into java code:

![](https://latex.codecogs.com/gif.latex?h(s)=&space;%5Cleft&space;(1+&space;%5Csum_%7Bi=0%7D%5E%7Bs.length()-1%7D&space;s.charAt(i)&space;%5Ccdot&space;256%5Ei&space;%5Cright&space;)&space;mod&space;(n) "h(s)= \left (1+ \sum_{i=0}^{s.length()-1)} s.charAt(i) \cdot 256^i \right ) mod (n)")

It would be much easier if I could use libraries such as Math.BigInteger but unfortunately I should do this without it. Some similar question on stackoverflow suggested to write an own bignum library but I want to do it without it.

Right now, my progress is at this step:

```
int h(String s) {
  long value = 1;
  int mod = ht.length;

  for (int i=0; i < s.length()-1; i++) {
     h += s.charAt(i) * Math.pow(256,i);
  }
  return (int) h % mod;
}

```

I know that the values of the power gets pretty quick out of the integer range so I thought about writing an own method which calculates the power and modulo of the value. My mathematical knowledge just isn't good enough to know when to use the modulo and how to easy things up.

Thanks in advance!