Java tutorial
//package com.java2s; import java.math.BigInteger; public class Main { public static int getNafWeight(BigInteger k) { if (k.signum() == 0) { return 0; } return k.shiftLeft(1).add(k).xor(k).bitCount(); } }