I have a question about how to implement unary encoding. For example: How can we differ n (non-negative) from n (strictly positive)? I don’t understand a bit. Please help me.
I have changed and written code.
public class unary {
public static void main (String[] args) {
int n = 10;
int i = 0;
String t = "";
while (i<n) {
t += "1";
i++;
}
t += "0";
System.out.println(n);
System.out.println("unary representation:");
System.out.println(t);
}
}
Result:
10
unary representation:
11111111110
Is it right like this?