Binary/Hex Literals Syntax


I was reading through some of the Integer bit_ methods and saw in the example:

2r10100.bit_set?(2) // returns true

What the? So reading up on the syntax page, found something new today :

r indicates ®adix / base – default 10 (decimal) if omitted. Ex: 2r binary & 16r hex. big-digit(s) vary by the radix used.


It was really exciting to find this syntax, it has already come in super handy.

2r1111 // 15
16rFF // 255
16rDEADBEEF // -559038737


The Primer in the online docs has even more info on Integer literals.

Also check out the Integer methods: binary(), octal(), hex(), radix()
And the String methods: int_binary(), int_octal(), int_hex(), int_radix()

I recommend that you read the entire online Primer if you haven’t already.

Lots of good stuff in there and it is still being added to. :madsci:


Somehow I have never seen this page, or perhaps a very early version of it long ago.

Truly a goldmine here… digit grouping seperator :heart:

Read the SkookumScript Primer to level up!