Pre-SIP: Support Binary Integer Literals

#1

Proposal

Support binary integer literals. For example, the binary literal 0b00101010 would have the integer value 42.

Motivation

Several other major languages support binary integer literals, including Java (as of Java 7), Python and Rust.

Interactions with Other Language Features

Like other integer literals, binary integer literals support separators (_), which can greatly enhance the readability of larger values (e.g. 0b_1110_1101_1011_0111).

Implementation

The implementation of binary integer literals is quite simple, and can be found at:

11 Likes
#2

SIP document PR:

#3

What would you think of supporting binary number literals via a string interpolator, alternatively?

val fortyTwo: Int = b"101010"
1 Like
#4

Why a string interpolator for binary, but not for hex in that case. I think it should be the same for both of them

3 Likes