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 stati开发者_运维知识库c 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?
Non-negative natural numbers includes 0. Strictly positive natural numbers does not. You don't need to differ non-negative from strictly-positive it is all about definition.
Unary string 0 represents the first natural number which is 0 if the domain is non-negative numbers or 1 if the domain is strictly-positive numbers.
The number 10 is represented as 1111111110
while dealing with strictly positive numbers or 11111111110
while dealing non-negative numbers.
精彩评论