java format 0 padded binary of integer

www.‮iruttual‬.com
java format 0 padded binary of integer
/**
 * @author lautturi.com 
 * Java example:  to get 0 padded binary representation of an integer in java
 */

import java.util.*;

public class Lautturi {

	public static void main(String[] args) {

		int num = 2;
		String str = String.format("%16s", Integer.toBinaryString(num)).replace(' ', '0');
		
		System.out.println(str);

	}
}

output:

0000000000000010
Created Time:2017-09-23 20:53:31  Author:lautturi