I have been working on turning a large javascript program into java. However I am unsure what is happening in these few lines here and how to turn it into java.

```
    int val = 0; //already turned to java

    int o = hash.length() % 4;  //already turned to java

for (var i = o > 0 ? o - 4 : 0; i < hash.length; i += 4) {
        val = ((val << 16) + parseInt(hash.substring(i, i+4), 16)) % mod;
    }

```

It is for a divisible function. hash is a string (specifically a sha256 string hash). Anyone able to help me figure out this weird forloop? Thanks.

I am aware that the parseInt is turning it into base 16, as I have translated that part other places in the code.