Post
Topic
Board Announcements (Altcoins)
diff_to_bits and bits_to_diff
by
Perp
on 30/09/2020, 07:39:31 UTC
Hello there!
For bitcoin:
difficulty = first_block_target / current_target
Is it correct for LTC? If not - how to calculate it?


More
For BTC (first block bits=0x1d00ffff)
target=
0x00000000ffff0000000000000000000000000000000000000000000000000000

for LTC if follow same way (first block bits=0x1e0ffff0)
target=
0x00000ffff0000000000000000000000000000000000000000000000000000000

That's true?

Also there in cgminer presents such code (from BTC asic driver):

static uint8_t diff_to_bits(double diff)
{
   uint64_t diff64;
   uint8_t i;

   diff /= 0.9999847412109375;
   diff *= (double)2147483648.0;
   if (diff > 0x8000000000000000ULL)
      diff = 0x8000000000000000ULL;
   /* Convert it to an integer */
   diff64 = diff;
   for (i = 0; diff64; i++, diff64 >>= 1);

   return i;
}

static double bits_to_diff(uint8_t bits)
{
   double ret = 1.0;

   if (likely(bits > 32))
      ret *= 1ull << (bits - 32);
   else if (unlikely(bits < 32))
      ret /= 1ull << (32 - bits);
   return ret;
}
I think that need to alter this line for LTC:
diff *= (double)2147483648.0; but how?

So how to adapt this code for LTC?

I'm trying to ask on different forums but no answer.
Somebody please help.
Thanks!