Here you can find the source of entropy(byte[] f)
public static float entropy(byte[] f)
//package com.java2s; //License from project: Apache License public class Main { public static float entropy(byte[] f) { int counts[] = new int[256]; float entropy = 0; float total = f.length; for (byte b : f) counts[b + 128]++;// w w w . j a va 2 s. c o m for (int c : counts) { if (c == 0) continue; float p = c / total; /* Compute entropy per bit in byte. * * To compute entropy per byte compute log with base 256 = log(p)/log(256). */ entropy -= p * Math.log(p) / Math.log(2); } return entropy; } }