Printing symbols

First of all, let's look how we can output symbols denoted by code points.

Your first option is to simply use hexadecimal code point number inside \x{}.

Let's look at some simple examples from the mathematic logic. To denote logical conjunction (more commonly known as AND operator), mathematicians use symbol , which has code point U+2227. So in Perl you should

binmode STDOUT, ":encoding(UTF-8)";

say "1 \x{2227} 0 = 0";

Exercise

Try to the write same example for logical disjunction (OR operator).

Hint: logical disjunction symbol comes right after the conjunction one in Unicode table.

binmode STDOUT, ":encoding(UTF-8)";

say '';

You can also use the name of a code point, which would make your script more readable. To do that you would use \N{} syntax instead of \x{} (if you are using version of Perl less than 5.16 you'll need to put use charnames; at the top of you script in order to use \N{}). The name of a code point could be seen directly in the Unicode standard or, for example, with App::Uni utility.

Remember exclusive disjunction operator? Yes, it's just good old XOR. As XOR is just an addition modulo 2, mathematicians write it as a plus sing in a circle — .

use charnames qw(:full);

binmode STDOUT, ":encoding(UTF-8)";

say "1 \N{CIRCLED PLUS} 0 = 1";

Exercise

Let's do some negation. Write an equation for negating bit 1.

Hint: use Unicode NOT SIGN.

use charnames qw(:full);

binmode STDOUT, ":encoding(UTF-8)";

say '';