@CC3/

Hashrate calculator

Java

No description

fork
loading
Files
  • Main.java
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60


class Main {


  public static void main(String[] args)  {


//input bits into the first field, and BTC hash rate in EH into second. Or just leave the second field as 0.0 to just get Elastos hashrate. Then press run.
  hashrate(402743569, 50);
   
  }












  public static void hashrate(int num, double btcHash ){
    Double hashRatio = 0.0;
    String str = Integer.toHexString(num);  //bits from decimal to hex

    //currentTarget = coefficient * 2^(0x8 * (exponent – 0x3))
    //coefficient is everything after the first two numbers in the hex form of bits.
    //exponent is the first two numbers of the hex form of bits 

    Double currentTarget = (double)Integer.parseInt(str.substring(2),16)* Math.pow(2,Integer.parseInt("08",16) * (Integer.parseInt(str.substring(0,2),16)- Integer.parseInt("03",16)));
    

    Double hashrate =   Math.pow(2,256)/((currentTarget+1.0)*120.0);
    
    if (btcHash == 0.0){
      

      System.out.println("\n" + Double.toString(hashrate).substring(0,1) + Double.toString(hashrate).substring(2,3) + "." + Double.toString(hashrate).substring(3,5) + "EH/s"  );
    }
    else {
     
      System.out.print("\n Elastos Hash Rate: ");
      System.out.println(Double.toString(hashrate).substring(0,1) + Double.toString(hashrate).substring(2,3) + "." + Double.toString(hashrate).substring(3,5) + "EH/s"  );
      System.out.print("\n Percentage of BTC hash rate: ");

      hashRatio = 100*hashrate/(btcHash*Math.pow(10,18));
      System.out.println(Double.toString(hashRatio).substring(0,5)  + "%"  );


    }

   

  }

}