Implement support for binary, octal and hex literals
I know VB supports hex literals but these need to be improved so instead of using the &h prefix, you could use a suffix:
Dim hexValue = 1F7h
The same way you could then implement both binary and octal literals:
Dim binValue = 01100011b
Dim octValue = 722o
Hey Xavier,
Good suggestion. As you mentioned VB already has hexadecimal and octal literals but no binary literals. It’s certainly a small feature we’re considering for a future release.
As I see it, VB is a language which strives to be both powerful for advanced developers while also approachable and learnable by new programmers. One of the early concepts we need to learn as new programmers is how binary numbers work and it’s unfortunate that the language today forces you to visualize that and do the translation in your head mentally. I’d certainly like to make that first-class (after all, who uses Octal anymore?).
Regarding the proposed syntax change the benefit seems minimal going from &HFF to FFH so we’re unlikely to make that change but it is worth considering relaxing the IDE’s pretty-lister forcing you to use upper-case, at least then you could type &hFF01 and &b10011101. I will say that one secondary feature something like binary literals makes more compelling is a digit grouping separator to make reading larger literals a little easier like &b1001 1101 or &b1001`1101 or 1`525`600 or &h00`CF`CF`CF. That’s something we’ve prototyped along side binary literals and I’m curious what you think about it.
Anyway, I’ve marked this suggestion “under review” and will update you as our thinking about it evolves.
Regards,
Anthony D. Green, Program Manager, Visual Basic & C# Languages Team
1 comment
-
Xavier
commented
These are great news Anthony.
The grouping feature will definitely be a welcome one... but, please, consider using spaces, otherwise it will look "too noisy".
As for the syntax change to identify between the different bases, if possible, at least consider it.
I (personally) find the "&" prefix extremely inconvenient.In any case, thank you for considering this "improvement"!