
On 9/5/05, Paul Mensonides <pmenso57@comcast.net> wrote:
Yes, you are right. I was thinking about actually reading the binary digits and *computing* the result. In other words, I was thinking about the completely general approach rather than leveraging the compatible base property of hexadecimal (or octal) and binary. However, the reason that I looked at it from that perspective is because it is possible to do arbitrary-precision arithmetic with the preprocessor (Chaos does it, for example), and I actually use binary literals as an example in the docs. With such arbitrary-precision support, you can read numbers in any base--hence my overlooking the obvious solution. :)
I really must take a look at Chaos sometime. On 9/5/05, Paul Mensonides <pmenso57@comcast.net> wrote:
And that doesn't really matter. Binary literals, AFAICT, are rarely useful for expressing actual numbers so much as sets of flags.
Yeah, that's pretty much the conclusion I've come to as well. On 9/5/05, Paul Mensonides <pmenso57@comcast.net> wrote:
Well, my only excuse for this is that I'd have to check the length of the sequence beforehand (or at least that it is less than two elements)--which takes time. Fixed in the CVS.
Great. On 9/5/05, Paul Mensonides <pmenso57@comcast.net> wrote:
Also note that I only allowed values which are 4 binary digits long. This was just a design choice as I believe it would be confusing having nibbles in the middle that have under 4 digits.
Note that one of the common uses of binary literals is as packed representations of several values. It isn't all that unusual to have a representation where the length in bits of each part are arbitrary. If I were you, I would allow such usage, but then you can't do a simple, direct mapping. You'd have to convert the input to (e.g.) a sequence of bits first, and the break it up into a mapping to hexadecimal digits. One of the advantages to doing binary literals with the preprocessor is that you *can* do this. The template mechanism cannot distinguish between 0001 and 01, but the preprocessor can. (Of course, it becomes unreasonable to allow bit groups that are larger than a byte.)
Yeah, I think I will do that. I also wanted to keep 4-bit sequences for clarity and to prevent people from making subtle mistakes (accidentally writing 7 1s instead of 8 1s, or something like that isn't too unreasonable and can be tough for a programmer to notice), however the more I think about it, the more I agree that I should allow representations as you describe, since the desire truely is there and it's not horribly difficult to provide the functionality. On 9/5/05, Paul Mensonides <pmenso57@comcast.net> wrote:
Allowing "1010 110" and having it mean "1010 0110" isn't just confusing, it's an abomination.
Yeah, and that's another thing that really bothered me about the template implementation. Using the preprocessor gets rid this. I must go, but I will update tomorrow. It's after 5:00 AM here and I have yet to sleep. Thanks for the feedback and suggestions. -- -Matt Calabrese