Litecoin/Bitcoin how divide uint256 target value on difficulty in C++

0 votes

I get unit256 class from litecoin wallet source, but this class dont have divide operator. So i convert uint256 to double which have implemintation in uint256 class

double getdouble() const
{
   double ret = 0.0;
   double fact = 1.0;
   for (int i = 0; i < WIDTH; i++) {
       ret += fact * pn[i];
       fact *= 4294967296.0;
   }
   return ret;
}
But now i need convert this huge double to hex string. This string will be represent target for miner, as far i understand. Or i need this double variable converts back to uint256 and thet get hex from it. 
Sep 12, 2018 in Blockchain by slayer
• 29,050 points
65 views

1 answer to this question.

0 votes

This is the solution:

void setdouble(double val)
{
    double ret = val;
    double fact = 1.0;
    for (int i = 0; i < WIDTH; i++) {
        double a = ret / fact;
        pn[i] =  (uint32_t)a;
        fact *= 4294967296.0;
    }
}
answered Sep 12, 2018 by digger
• 27,620 points

Related Questions In Blockchain

+1 vote
2 answers

How to return value from a chaincode in Hyperledger Fabric?

Hyperledger Fabric supports only 2 types of ...READ MORE

answered Jun 13, 2018 in Blockchain by Perry
• 17,010 points
694 views
0 votes
1 answer

How are unique public address generated in bitcoin?

In brief, the public addresses are generated ...READ MORE

answered Jul 16, 2018 in Blockchain by slayer
• 29,050 points
36 views
0 votes
1 answer
0 votes
1 answer

How to use bitcoin price as place holder in php?

You can do it by providing an ...READ MORE

answered Aug 21, 2018 in Blockchain by digger
• 27,620 points
32 views
0 votes
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured by TLS encryption in hashgraph architecture-hashgraph, ...READ MORE

answered Aug 6, 2018 in Blockchain by ariaholic
• 7,320 points
56 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
105 views
0 votes
1 answer
0 votes
1 answer

How i can use nodejs to watch transactions in bitcoin network?

you can use  const Socket = require('blockchain.info/Socket'); const mySocket ...READ MORE

answered Jul 9, 2018 in Blockchain by digger
• 27,620 points
34 views
0 votes
1 answer

How to get current value of bitcoin?

You can use json_decode to transform it ...READ MORE

answered Aug 20, 2018 in Blockchain by digger
• 27,620 points
40 views