Suggestion: Binary Integers

Discuss the future of the AutoHotkey language
Ursi
Posts: 18
Joined: 16 Oct 2018, 14:11
GitHub: Ursi

Suggestion: Binary Integers

16 Oct 2018, 14:18

I was kinda surprised when I realized there was no support for binary integers—not even in format. I think a 0b prefix, or at least a b format type, would be great.
User avatar
jeeswg
Posts: 5260
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Suggestion: Binary Integers

16 Oct 2018, 16:03

- I have said that 0b... would be nice to match 0x... which we already have.
- Is it especially common? I know that Java and Python support it, but not C++.
- I would definitely like something like BaseToDec and DecToBase (in some form). Out of interest, do you actually use 0b... that often? Thanks.
homepage | tutorials
[code boxes are currently not working 100%]
[click the 'Reply with quote' button on a post to see the full indented text]
Ursi
Posts: 18
Joined: 16 Oct 2018, 14:11
GitHub: Ursi

Re: Suggestion: Binary Integers

16 Oct 2018, 17:24

I do not use it often, but recently something got me looking for it, only to realize it wasn't there (I don't remember what that thing was). But octal is a format type, is octal used more than binary?
User avatar
jeeswg
Posts: 5260
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Suggestion: Binary Integers

16 Oct 2018, 17:29

- The Format function accepts octal, good point. Once you add a letter to Format, there's no turning back. So even though I think adding b for binary might be a good idea, I'm cautious. (Dec to/from Base functions, like I mentioned, would definitely be welcome.)
- I use bin, dec, hex regularly, but never oct, if anyone would like to say why octal is useful. Those are the classic 4 that usually have special functions/syntax.
- One time when 0b would have been useful was while I was writing my CRC-32 tutorial.
homepage | tutorials
[code boxes are currently not working 100%]
[click the 'Reply with quote' button on a post to see the full indented text]
lexikos
Posts: 6200
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Suggestion: Binary Integers

16 Oct 2018, 21:25

Most of the formatting for each value is done with a C runtime function similar to printf. All of the type characters and flags supported by Format except for U, L and T are implemented by passing them to this function. Octal is supported merely because the Microsoft's printf supports it; on our end it's just a case of adding one letter to the string of acceptable type characters. I'm not aware of any C runtime functions that support binary literals (parsing or formatting), and I am not inclined to write code for it myself since I won't find it useful.

Return to “AutoHotkey v2 Development”

Who is online

Users browsing this forum: No registered users and 5 guests