How to aproach this in android? signed byte
<p>I have a piece of problem that I want to achieve in android. </p>

<blockquote>
  <p>The formula is</p>
  
  <ol>
  <li>Server Seed + Client Seed (->byte[4]) + Bet Number (->byte[4])</li>
  <li>Double SHA2-512 hash the result</li>
  <li>Keep taking groups of 3 bytes and converting to an integer, until a value less than 16 million is found. If you run out of bytes, hash it
  again and start over.</li>
  <li>Find the value's modulus of 1 million</li>
  <li>The modulus is the bet result!</li>
  </ol>
</blockquote>

<p>Which have an example code in C#</p>

<pre><code>static bool VerifyBetResult(string serverSeed, int clientSeed, int betNumber,
                            long betResult, string serverSeedHash = null)
{
    Func&lt;string, byte[]&gt; strtobytes = s =&gt; Enumerable
        .Range(0, s.Length / 2)
        .Select(x =&gt; byte.Parse(s.Substring(x * 2, 2), NumberStyles.HexNumber))
        .ToArray();
    byte[] server = strtobytes(serverSeed);
    byte[] client = BitConverter.GetBytes(clientSeed).Reverse().ToArray();
    byte[] num = BitConverter.GetBytes(betNumber).Reverse().ToArray();
    byte[] serverhash = serverSeedHash == null ? null : strtobytes(serverSeedHash);
    byte[] data = server.Concat(client).Concat(num).ToArray();
    using (SHA512 sha512 = new SHA512Managed())
    {
        if (serverhash != null)
            using (SHA256 sha256 = new SHA256Managed())
                if (!sha256.ComputeHash(server).SequenceEqual(serverhash))
                    throw new Exception("Server seed hash does not match server seed");
        byte[] hash = sha512.ComputeHash(sha512.ComputeHash(data));
        while (true)
        {
            for (int x = 0; x &lt;= 61; x += 3)
            {
                long result = (hash[x] &lt;&lt; 16) | (hash[x + 1] &lt;&lt; 8) | hash[x + 2];
                if (result &lt; 16000000)
                    return result % 1000000 == betResult;
            }
            hash = sha512.ComputeHash(hash);
        }
    }
}
</code></pre>

<p>Using these values</p>

<pre><code>serverSeed = e600f76aa6c520dff7db34559bd05cb1048b1830a07cd81844147a19048fc9be;
clientSeed = 443944;
betNumber = 0;
serverHash = ca90022ac66a6a77d8b5072e101bff505c2bff552b1b9a0785f0c438d5b6228f;
</code></pre>

<p><strong>I want to find the (result % 1000000) which should be = 563383</strong></p>

<p>But I got -<strong>25564</strong> and the serverHash does not match the serverSeed when hashing the seed to sha256</p>

<p><strong>Update</strong>
This is my code:</p>

<pre><code>private byte[] reverse(byte[] b){
    int i = b.length - 1;
    byte newB[] = new byte[4];
    for(int x = 0; x &lt; b.length; x++){
        newB[x] = b[i];
        i--;
    }
    return newB;
}

private byte[] strToByte(String s) {
    int len = s.length();
    byte[] data = new byte[len/2];

    for(int i = 0; i &lt; len; i+=2){
        data[i/2] = (byte) ((Character.digit(s.charAt(i), 16) &lt;&lt; 4) + Character.digit(s.charAt(i+1), 16));
    }
    return data;
}

private long verifyBet(){
    //MessageDigest md256 = null;
    MessageDigest md512 = null;
    try {
        //md256 = MessageDigest.getInstance("SHA-256");
        md512 = MessageDigest.getInstance("SHA-512");
    } catch (Exception e) {
        e.printStackTrace();
    }
    String //res = "ServerSeed = ",
        sSeed = "e600f76aa6c520dff7db34559bd05cb1048b1830a07cd81844147a19048fc9be";
        //sHash = "ca90022ac66a6a77d8b5072e101bff505c2bff552b1b9a0785f0c438d5b6228f";
    int cSeed = 443944,
        num = 0;
    byte serverSeed[] = strToByte(sSeed),
        //serverHash[] = strToByte(sHash),
        clientSeed[] = reverse(ByteBuffer.allocate(4).putInt(cSeed).array()),
        betNumber[] = reverse(ByteBuffer.allocate(4).putInt(num).array());
    byte data[] = ByteBuffer.allocate(serverSeed.length + clientSeed.length + betNumber.length)
        .put(serverSeed).put(clientSeed).put(betNumber).array();
    data = md512.digest(data);
    data = md512.digest(data);
    long secret = 0;
    boolean found = false;
    while(!found){
        for(int x = 0; x &lt;= 61; x += 3){
            long result = (data[x] &lt;&lt; 16 | data[x+1] &lt;&lt; 8) | data[x+2];
            if (result &lt; 16000000){
                secret = result % 1000000;
                found = true;
            }
        }
        data = md512.digest(data);
    }
    return secret;
}
</code></pre>

<p>After much more research I found that <code>byte</code> in <code>java</code> is <code>signed</code> while the code I am basing from is calculating in <code>unsigned</code> <code>byte</code> which is why I am getting result in negative..</p>

<p><strong>How can I get set of bytes in 'unsigned' form?</strong></p>