SIP-42 - Support Binary Integer Literals

Language

By: NthPortal

History

Date Version
Jul 27th 2019 Initial Draft

Your feedback is welcome! If you’re interested in discussing this proposal, head over to this Scala Contributors thread and let me know what you think.

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), Kotlin, 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 https://github.com/scala/scala/pull/8275.