I have a list of names, ArrayList<String> names. For example:
ArrayList<String> names= new ArrayList<String>();
names.add("foo1");
names.add("foo2");
names.add("foo3");
names.add("foo4");
names.add("foo5");
Then I can encode these five names into binary numbers with (ceiling(log(5))=) 3 digits: foo1=000, foo2=001, foo3=010, foo4=011, foo5=100. I want a function which looks like public int[] return_binary_encoding(String name, ArrayList<String> names) , where name is in names.
String name? What is its significance in the question you asked? Have you tried anything - some lines of code?nameis in thenames. Ok, now I feel this was a stupid question since I can get the index ofnamebynames.indexOf(name)and then I just need to convert it to a binary number with log(k) digits. right?Integer.toBinaryString(names.indexOf(name))and then I just need to add enough 0s to have a binary number with log(k) digits. right?