Skip to content

Instantly share code, notes, and snippets.

@yowcow
Last active May 3, 2018 09:38
Show Gist options
  • Save yowcow/cc8ec530ab063f7a40bf699969378efb to your computer and use it in GitHub Desktop.
Save yowcow/cc8ec530ab063f7a40bf699969378efb to your computer and use it in GitHub Desktop.
Binary/Decimal/Hex in Perl 6
use v6;
# Hex => Dec
:16("ff").base(10); # 255
# Dec => Bin
:10("10").base(2); # 1010
# Bin => Hex
:2("1111").base(16); # F
# Bitwise AND
200 +& 13; # 8
:10("200").base(2); # 11001000
:10("13").base(2); # 1101
#-----------------------------
# 00001000
:2("00001000").base(10); # 8
# Bitwise OR
200 +| 13; # 205
:10("200").base(2); # 11001000
:10("13").base(2); # 1101
#-----------------------------
# 11001101
:2("11001101").base(10); # 205
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment