Here you can find the source of distance(BigInteger a, BigInteger b)
public static int distance(BigInteger a, BigInteger b)
//package com.java2s; //License from project: Open Source License import java.math.BigInteger; public class Main { public static int M; public static int distance(BigInteger a, BigInteger b) { int ia = a.intValue(); int ib = b.intValue(); if (ib >= ia) return ib - ia; return ib + (int) Math.pow(2, M) - ia; }//from ww w. ja v a 2 s . co m }