Pre-SIP: Support Binary Integer Literals

It’d probably be easier to define a .toInt on Binary, otherwise you’d have to import the feature flag for implicit conversions anywhere you want to adapt the types (which is a pain in the neck).

Otherwise, I agree it’s probably the simplest way to differentiate them.


I just recently ported the hex and bin macro-based interpolators to Dotty:

scala> import scodec.bits._

scala> val b = hex"deadbeef"
val b: scodec.bits.ByteVector = ByteVector(4 bytes, 0xdeadbeef)

scala> val c = bin"1100110"
val c: scodec.bits.BitVector = BitVector(7 bits, 0xcc)

Per a suggestion from @soronpo, I was able to get FromDigits for ByteVector working as well:

This gives usage like:

scala> import scodec.bits._

scala> val b: ByteVector = 0x00112233_44556677_8899aabb_ccddeeff_fedba098
val b: scodec.bits.ByteVector = ByteVector(20 bytes, 0x00112233445566778899aabbccddeefffedba098)

I’d love to see support for radix 2 with FromDigits via 0b prefix.

Aside: I noticed when using hex literals, the string passed to fromDigits includes a leading 0. E.g., 0xdeadbeef results in a digits string “0deadbeef”.