Here you can find the source of getNafWeight(BigInteger k)
public static int getNafWeight(BigInteger k)
//package com.java2s; import java.math.BigInteger; public class Main { public static int getNafWeight(BigInteger k) { if (k.signum() == 0) { return 0; }/* w w w . java2 s .co m*/ BigInteger _3k = k.shiftLeft(1).add(k); BigInteger diff = _3k.xor(k); return diff.bitCount(); } }