Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for literal hexadecimal, binary and octal numbers #69

Closed
3 tasks done
perlun opened this issue Sep 5, 2020 · 0 comments · Fixed by #220
Closed
3 tasks done

Add support for literal hexadecimal, binary and octal numbers #69

perlun opened this issue Sep 5, 2020 · 0 comments · Fixed by #220
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Milestone

Comments

@perlun
Copy link
Collaborator

perlun commented Sep 5, 2020

Goals

It should be possible to specify literal hexadecimal, binary and octal integer and long values in Perlang.

Non-goals

Supporting mechanisms like incbin in NASM is out of scope for this issue.

Implementation details

Hexadecimal integers are simple, since there is a uniform notation for them supported by most languages: 0x42 => literal hexadecimal 42, i.e. the decimal value 66. (We can either be strict and enforce a lowercase 0x here or be relaxed and support 0X prefixes as well; Ruby as C# seem to support both.)

Binary numbers are not supported by all languages, but C# seems to support the 0b (or 0B) prefix for this. We could do the same.

Octal literals are interestingly enough not supported in C#. Many other languages like Ruby, Python and good-old C supports octal notation using a single 0 prefix - 0755 is treated as an octal number, equivalent to 493 in decimal notation.

However, the "plain-zero" prefix is problematic in that it is too ambiguous; it's not obvious enough to any new developer unfamiliar with your language from beforehand that 042 is in fact, not the literal number 42 but instead 34. Perhaps to avoid this, the Rust language chose a different approach 1 2 - it uses 0o42 for octal notation. (Later edit: I discovered that this syntax is supported in Ruby as well.)

While this might look a bit "odd" at first (for people used to simple 0-prefixing octal numbers), it does make quite a bit of sense in being:

  • more consistent with other prefixes (0x and 0b)
  • less confusing to beginners
  • mildly annoying to people who would have preferred plain 0755 notation. They can still write Unix file permissions in a natural way, they just have to do some very minor learning.

Suggested syntax

We can either implement all of these in a single PR, or do a separate PR for each notation.

@perlun perlun added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels Sep 5, 2020
@perlun perlun added this to the 0.2.0 milestone Oct 19, 2020
perlun added a commit that referenced this issue Oct 11, 2021
@perlun perlun changed the title Add support for literal hexedecimal, binary and octal numbers Add support for literal hexadecimal, binary and octal numbers Oct 11, 2021
@perlun perlun modified the milestones: 0.2.0, 0.1.0 Oct 13, 2021
perlun added a commit that referenced this issue Oct 13, 2021
perlun added a commit that referenced this issue Oct 13, 2021
Last step towards closing #69, building on top of #217 and #219.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant