Binary Literals

As I understand go does not support binary literals such as 0b01101100.

The discussions so far mention two workarounds, either use strtoul or define consts such as b01101100 (works for 8bit, afterwards it becomes silly).

Benefits of literals:

  • makes certain code way more readable (yes I can convert to hex in my head, but it’s non-obvious to the reader)
  • allows untyped consts (compared to strtoul)

Drawbacks:

  • yet another literal

Are there any plans for binary literals? Or is there a compelling reason not to have them?

From proposal: different octal base literal representation · Issue #12711 · golang/go · GitHub

both the ‘o’ for octal and ‘b’ for binary notation were also discussed in the design of Go. It’s simply not enough bang for the buck.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.