Here you can find the source of doubleToUnary(int max, double num)
public static char[] doubleToUnary(int max, double num)
//package com.java2s; //License from project: Open Source License public class Main { public static char[] doubleToUnary(int max, double num) { char[] chars = new char[max]; int discrNum = (int) num; // Fill with ones for (int i = 0; i <= num; ++i) { chars[i] = '1'; }/*from w w w . jav a 2 s. co m*/ // Fill with zeros for (int i = discrNum + 1; i < max; ++i) { chars[i] = '0'; } return chars; } }