Topic: Number representation (was: proposal extension to #undef syntax)


Author: Christopher Eltschka <celtschk@physik.tu-muenchen.de>
Date: 1998/11/24
Raw View
Paul D. DeRocco wrote:
>
> Siemel Naran wrote:
> >
> > An old assembler for the Apple I had used '%' for binary numbers.
> > Is this the standard symbol for binary?
>
> I've seen that before, too. To be consistent with C/C++, I suggest a
> prefix of either 0b or 0y for binary. The b stands for binary, but could
> be mistaken by a human reader for a hex digit. The y is the last letter
> of binary (just as x is the last letter of hex), but it looks enough
> like an x that it might occasionally be mistaken for an x. I gravitate
> toward 0y, but am not a zealot about it.

But "hex" is just an abbreviation to "hexadecimal". So the "y"
for "binary" would be equivalent to an "l" for hexadecimal.

The analog to "hex" would be "bin", and therefore the analog to 0x
would be 0n.

However, I'd vote for a more general approach: Let the user specify
an arbitrary base (well, not completely arbitrary, since we have
only a limited set of characters; up to 36 would make sense).
The Extended Pascal standard already has this, with the notation
base#num (f.ex. 147 is 2#10010011 is 8#223 is 16#93 is 11#124
is 13#b4). Now, in C++ # already has a meaning, so another
character needs to be used. What about using $ for it?
It would not break anything (the standard doesn't have that
letter at all, and implementations using it in identifiers
won't break either, since identifiers may not start with a digit).

This way, 2$10011 == 3$201 == 4$103 == 5$34 == 6$31 == 7$25 == 8$23
(== 023) == 9$21 == 10$19 (==19) == 11$18 == 12$17 == ... == 15$14
== 16$13 (==0x13) == 17$12 == ... == 19$10 == 20$j == 21$j == ...

(It would make sense to demand that the base is specified in
decimal, although numbers like 0xA$20 or even 2$100$427 would
in theory be unambiguous, too)
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]