How to write a binary literal in Dart

Viewed 1856

How do you write a Binary Literal in Dart?

I can write a Hex Literal like so:

Int Number = 0xc

If I try the conventional way to write a Binary Literal:

Int Number = 0b1100

I get an error. I've tried to look it up, but I've not been able to find any information other than for hex.

2 Answers

There are currently no built-in binary number literals in Dart (or any base other than 10 and 16).

The closest you can get is: var number = int.parse("1100", radix: 2);.

Related