Topic: Binary number syntax?


Author: ahp6@email.byu.edu ("Adam H. Peterson")
Date: Thu, 13 May 2004 21:15:05 +0000 (UTC)
Raw View
>>"0x" set a precedent of using the third letter of the word, though. ;-)
>>
>>Seriously, "0b" and "0o" would be more sensible.
>
>
> My vote is for '0b'. Nothing about '0o' implies 'binary' to me. And
>     while my most often used fonts make '0' readily distinguishable
>     from 'o', not all fonts do.

I think the intent was for 0b to imply binary and 0o to imply octal.

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: llewelly.at@xmission.dot.com (llewelly)
Date: Fri, 14 May 2004 00:08:21 +0000 (UTC)
Raw View
ahp6@email.byu.edu ("Adam H. Peterson") writes:

>>>"0x" set a precedent of using the third letter of the word, though. ;-)
>>>
>>>Seriously, "0b" and "0o" would be more sensible.
>> My vote is for '0b'. Nothing about '0o' implies 'binary' to me. And
>>     while my most often used fonts make '0' readily distinguishable
>>     from 'o', not all fonts do.
>
> I think the intent was for 0b to imply binary and 0o to imply octal.

Thank you, I can see that now. But we already have a syntax for octal
    literals.

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: barmar@alum.mit.edu (Barry Margolin)
Date: Fri, 14 May 2004 00:43:41 +0000 (UTC)
Raw View
In article <86n04banp0.fsf@Zorthluthik.local.bar>,
 llewelly.at@xmission.dot.com (llewelly) wrote:

> ahp6@email.byu.edu ("Adam H. Peterson") writes:
>
> >>>"0x" set a precedent of using the third letter of the word, though. ;-)
> >>>
> >>>Seriously, "0b" and "0o" would be more sensible.
> >> My vote is for '0b'. Nothing about '0o' implies 'binary' to me. And
> >>     while my most often used fonts make '0' readily distinguishable
> >>     from 'o', not all fonts do.
> >
> > I think the intent was for 0b to imply binary and 0o to imply octal.
>
> Thank you, I can see that now. But we already have a syntax for octal
>     literals.

True, but wouldn't it be nice to have a consistent syntax across the
board for all the different bases?

It's clearly too late to change it, but the syntax for octal numbers has
always seemed very non-intuitive to me.  What does leading zeroes have
to do with selecting a radix?

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: ng@spfweb.co.uk (Steve Folly)
Date: Fri, 14 May 2004 03:15:26 +0000 (UTC)
Raw View
On 13/5/04 6:43 am, in article
slrnca4j9h.cvo.do-not-spam-benh@shadbolt.i.decadentplace.org.uk, "Ben
Hutchings" <do-not-spam-benh@bwsint.com> wrote:

> Barry Margolin wrote:
>> In article <MVFmc.10789$Hs1.432@newsread2.news.pas.earthlink.net>,
>>  pderocco@ix.netcom.com ("Paul D. DeRocco") wrote:
>>
>>> It seems odd that C/C++ doesn't have a binary number notation. Prefixing a
>>> binary number with 0n would seem the most reasonable syntax. Also, it would
>
> Similarly there should be the option of using "0t" instead of just "0"
> as a prefix for octal numbers.
>
>> 0b seems like a more appropriate prefix to me.
> <snip>
>
> "0x" set a precedent of using the third letter of the word, though. ;-)

I always thought it was 'ex. Innit? :)


Steve.

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: pderocco@ix.netcom.com ("Paul D. DeRocco")
Date: Fri, 7 May 2004 18:06:36 +0000 (UTC)
Raw View
It seems odd that C/C++ doesn't have a binary number notation. Prefixing a
binary number with 0n would seem the most reasonable syntax. Also, it would
be nice if long numbers could be broken up into groups of digits by
underscores, like:

    1_000_000_000
    0xFFFF_FFFF
    0n1000_0000_0000_0000

This wouldn't conflict with any existing legal syntax, and makes numbers so
much more readable.

--

Ciao,               Paul D. DeRocco
Paul                mailto:pderocco@ix.netcom.com

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: ng@spfweb.co.uk (Steve Folly)
Date: Fri, 7 May 2004 21:06:44 +0000 (UTC)
Raw View
On 7/5/04 7:06 pm, in article
MVFmc.10789$Hs1.432@newsread2.news.pas.earthlink.net, ""Paul D. DeRocco""
<pderocco@ix.netcom.com> wrote:

> It seems odd that C/C++ doesn't have a binary number notation. Prefixing a
> binary number with 0n would seem the most reasonable syntax. Also, it would
> be nice if long numbers could be broken up into groups of digits by
> underscores, like:
>
>   1_000_000_000
>   0xFFFF_FFFF
>   0n1000_0000_0000_0000
>
> This wouldn't conflict with any existing legal syntax, and makes numbers so
> much more readable.

Should this work for stream input (and output too?)

What if you're reading numbers from a stream and it's formatted such that
your numbers are delimited by underscores?

Example: [excuse any syntax errors!]

string s( "1_000_000_000" );
istringstream is( s );

int a, b, c, d;
char delim;

Is >> a >> delim >> b >> delim >> c >> delim;

What's the result?



I could be persuaded that cases where underscores are used like this are
probably few and far between.

Then there's manipulators to allow or generate the underscores.

Don't get me wrong, I'm not against the idea, I've worked with Ada and it
worked well there. Just throwing some more ideas in...


Steve.

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: barmar@alum.mit.edu (Barry Margolin)
Date: Fri, 7 May 2004 21:09:57 +0000 (UTC)
Raw View
In article <MVFmc.10789$Hs1.432@newsread2.news.pas.earthlink.net>,
 pderocco@ix.netcom.com ("Paul D. DeRocco") wrote:

> It seems odd that C/C++ doesn't have a binary number notation. Prefixing a
> binary number with 0n would seem the most reasonable syntax. Also, it would

0b seems like a more appropriate prefix to me.

> be nice if long numbers could be broken up into groups of digits by
> underscores, like:
>
>     1_000_000_000
>     0xFFFF_FFFF
>     0n1000_0000_0000_0000
>
> This wouldn't conflict with any existing legal syntax, and makes numbers so
> much more readable.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: "Pavel Vozenilek" <pavel_vozenilek@yahoo.co.uk>
Date: 10 May 2004 06:20:11 GMT
Raw View
"Steve Folly" <ng@spfweb.co.uk> wrote:

> > Also, it would
> > be nice if long numbers could be broken up into groups of digits by
> > underscores, like:
> >
> >   1_000_000_000
..
> Should this work for stream input (and output too?)
>

If this feature gets limited to code, it would have no
impact on streams/formatting/etc.

/Pavel


---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: llewelly.at@xmission.dot.com (llewelly)
Date: Mon, 10 May 2004 23:22:17 +0000 (UTC)
Raw View
"Pavel Vozenilek" <pavel_vozenilek@yahoo.co.uk> writes:

> "Steve Folly" <ng@spfweb.co.uk> wrote:
>
>> > Also, it would
>> > be nice if long numbers could be broken up into groups of digits by
>> > underscores, like:
>> >
>> >   1_000_000_000
> ..
>> Should this work for stream input (and output too?)
>>
>
> If this feature gets limited to code, it would have no
> impact on streams/formatting/etc.

Arguably that would be an udesirable inconsistency.

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: pavel_vozenilek@yahoo.co.uk ("Pavel Vozenilek")
Date: Tue, 11 May 2004 23:08:47 +0000 (UTC)
Raw View
"llewelly" <llewelly.at@xmission.dot.com> wrote:

> >> Should this work for stream input (and output too?)
> >
> > If this feature gets limited to code, it would have no
> > impact on streams/formatting/etc.
>
> Arguably that would be an udesirable inconsistency.
>
It is possible now to specify number in hex (in code),
yet reading/writing hex in stream requires explicit action.

Surely some new formatting flags can be invented for
underscore-enhanced numbers.

/Pavel



---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: do-not-spam-benh@bwsint.com (Ben Hutchings)
Date: Thu, 13 May 2004 05:43:27 +0000 (UTC)
Raw View
Barry Margolin wrote:
> In article <MVFmc.10789$Hs1.432@newsread2.news.pas.earthlink.net>,
>  pderocco@ix.netcom.com ("Paul D. DeRocco") wrote:
>
>> It seems odd that C/C++ doesn't have a binary number notation. Prefixing a
>> binary number with 0n would seem the most reasonable syntax. Also, it would

Similarly there should be the option of using "0t" instead of just "0"
as a prefix for octal numbers.

> 0b seems like a more appropriate prefix to me.
<snip>

"0x" set a precedent of using the third letter of the word, though. ;-)

Seriously, "0b" and "0o" would be more sensible.

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: dont.spam.me@ns3.domainsite.com (Xenos)
Date: Thu, 13 May 2004 15:16:01 +0000 (UTC)
Raw View
"Ben Hutchings" <do-not-spam-benh@bwsint.com> wrote in message
news:slrnca4j9h.cvo.do-not-spam-benh@shadbolt.i.decadentplace.org.uk...

> Seriously, "0b" and "0o" would be more sensible.

0o?  I'd hate to debug code with that kind of syntax.




---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: llewelly.at@xmission.dot.com (llewelly)
Date: Thu, 13 May 2004 20:37:59 +0000 (UTC)
Raw View
do-not-spam-benh@bwsint.com (Ben Hutchings) writes:

> Barry Margolin wrote:
>> In article <MVFmc.10789$Hs1.432@newsread2.news.pas.earthlink.net>,
>>  pderocco@ix.netcom.com ("Paul D. DeRocco") wrote:
>>
>>> It seems odd that C/C++ doesn't have a binary number notation. Prefixing a
>>> binary number with 0n would seem the most reasonable syntax. Also, it would
>
> Similarly there should be the option of using "0t" instead of just "0"
> as a prefix for octal numbers.
>
>> 0b seems like a more appropriate prefix to me.
> <snip>
>
> "0x" set a precedent of using the third letter of the word, though. ;-)
>
> Seriously, "0b" and "0o" would be more sensible.

My vote is for '0b'. Nothing about '0o' implies 'binary' to me. And
    while my most often used fonts make '0' readily distinguishable
    from 'o', not all fonts do.

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]