Ethereum has their own standard for Hex encoding / decoding.
You can use Nethereum for this.
From the screen shot to get your work:
using System;
using System.Text;
using Nethereum.Hex.HexConvertors.Extensions;
using System.Threading.Tasks;
using Nethereum.Web3;
using Nethereum.RPC.Eth.Blocks;
using Nethereum.Hex.HexTypes;
public class HexDecoding
{
private static async Task Main(string[] args)
{
var web3 = new Web3("your url");
var work = await web3.Eth.Mining.GetWork.SendRequestAsync();
Console.WriteLine(work.Length);
}
}
And to do the calculation, depending in your endianism you can do something like this:
using System;
using System.Text;
using Nethereum.Hex.HexConvertors.Extensions;
using System.Threading.Tasks;
using Nethereum.Web3;
using Nethereum.RPC.Eth.Blocks;
using Nethereum.Hex.HexTypes;
using System.Numerics;
public class HexDecoding
{
private static async Task Main(string[] args)
{
var difficulty = 23142114022743;
var target = BigInteger.Divide(BigInteger.Pow(2, 256), difficulty);
Console.WriteLine(target);
// A simple check on endianism and reversing
byte[] bytes;
Console.WriteLine(BitConverter.IsLittleEndian);
if (BitConverter.IsLittleEndian)
bytes = target.ToByteArray().Reverse().ToArray();
else
bytes = target.ToByteArray().ToArray();
Console.WriteLine(bytes.ToHex());
//Another option using .Net core now (awesome)
Console.WriteLine(target.ToByteArray(true, true).ToHex()); // new .net core
//Final option if you are using Nethereum and not using .Net core
Console.WriteLine(HexBigIntegerConvertorExtensions.ToByteArray(target, false).ToHex());
//0x00000000000c29b321174712bb7ca6dd0896b050e18d4c7e13df4c1aee84f2c0
//0x00000000000c29b321174712bb7ca6dd0896b050e18d4c7e13df4c1aee84f2c0
}
}