.NET introduces binary literals
With the introduction of the new Roslyn compiler platform for Visual Studio, the .NET languages team has, finally, made available the support to declare and use binary literals for VB.NET.
Back in 2011 I posted a request to the .NET languages team to implement support for binary literals and also took the liberty to suggest some improvements to the syntax currently used by VB.NET to declare these literals.
About a year later, I decided to come up with my own solution.
It did the job (kind of) but because of the way it worked, not even me ever used it in any of my personal projects.
So now, thanks to Roslyn, you can declare variables and use constants expressed as binary values, and it’s as simple as this:
Dim value As Integer = &B010011
Although the syntax improvements won’t be implemented, they did actually come up with a very nice idea of their own: grouping. And it is awesome!
Grouping allows you to use blank spaces (other characters are being considered, so this might change in future releases), to separate groups of digits; for example, the above example could be rewritten as:
Dim value As Integer = &B 01 00 11
This grouping enhancement is supported across several types of literals:
Dim value As Integer = &F AA 55 AA 55 ' Hexadecimal Dim value As Integer = 423 258 ' Decimal Dim value As Integer = &O 175 041 ' Octal
If you haven’t tried Roslyn already, I very much encourage you to do so.
The aforementioned changes are just a (very) small portion of the cool things the .NET team is doing.
Featured Image Credit: ThinkGeek.com
Recent Comments