Here you can find the source of getDifficulty(long compactTarget)
public static BigDecimal getDifficulty(long compactTarget)
//package com.java2s; //License from project: Open Source License import java.math.BigDecimal; public class Main { /**//from w w w. j av a 2 s .co m * Returns PoW difficulty (bdiff) for the target specified in a compact form known as "bits" in Bitcoin Core. */ public static BigDecimal getDifficulty(long compactTarget) { // TODO: this is about three orders of magnitude away from overflowing // TODO: optimize, see https://en.bitcoin.it/wiki/Difficulty double maxbody = Math.log(0x00ffff); double scaland = Math.log(256); double diff = Math.exp(maxbody - Math.log(compactTarget & 0x00ffffff) + scaland * (0x1d - ((compactTarget & 0xff000000) >> 24))); return BigDecimal.valueOf(diff); } }