Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C > binary literals...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 63 of 99 Topic 26092 of 26972
Post > Topic >>

binary literals (was Re: lcc first experience)

by Chris Torek <nospam@[EMAIL PROTECTED] > May 8, 2008 at 02:18 AM

>Eric Sosman <esosman@[EMAIL PROTECTED]
> writes:
>>     In all my days, I've only encountered one language that
>> sup****ted literals in all the bases 2,4,8,16 ...

In article <87ve1psi15.fsf@[EMAIL PROTECTED]
>
Keith Thompson  <kst-u@[EMAIL PROTECTED]
> wrote:
>Ada sup****ts all bases 2 through 16:
>2#11001001# -- binary
>3#12012#    -- trinary (ternary?)
>10#42#      -- equivalent to just 42
>16#1.23#e10 -- hexadecimal floating-point (1.13671875 * 16**10)
>
>One advantage is uniformity; there's no special-case syntax for each
>base.

Indeed.

One could squeeze arbitrary integer bases into C (as it stands
today) using (eg) 0r, with the radix and number separated by another
punctuator that can be found in what is currently a valid "pp-number"
but not-valid integer, e.g., another r, or a decimal point, or
some such:

    0r2r1101001
    0r8.391

but binary seems to be the only one people miss, and 0b<digit-sequence>
is the "obvious" way to do it:

>[a]nd Perl sup****ts C-style literals plus binary with the "0b..."
>syntax. ...  (even in Ada, I've rarely if ever seen bases other
>than 2, 8, 10, and 16 outside test cases).  But IMHO binary constants
>using the 0b syntax would be a nice addition ...

Not only have I wanted them, I have even implemented them (though
not in C).  However:

>... On the other hand, we've gotten along for decades
>without them, and new features quite properly need to meet a high
>burden before being standardized.

as it turns out, binary constants like this are actually quite
error-prone.  I discovered it was better to go back to hexadecimal
constants in quite a few cases.  The binary constants were mainly
useful in short binary numbers (where hex-vs-binary became pretty
much a matter of taste).

If C were to steal another feature from Ada, we could fix this,
*and* the equivalent problem with other large constants (in any
base), by adding "_" as an ignored digit separator.  Then we could
write:

    0b1101_0110_0010_1101_1000_0101_1110_0000_0001_1110_1111_0001_0011

or:

    0xd62d_85e0_ef13

both of which are (I believe) superior to the equivalent versions
without underscores.  I also find:

    12_345_678_997

a little more "obvious" than:

    12345678997

Note that C89's "pp-number" tokens leave enough leeway to add both
binary constants (with 0b) *and* group separators (with _).  Perhaps
I should add them to gcc (with an appropriate "extension" warning),
and try to get them into C1x. :-)
-- 
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W)  +1 801 277 2603
email: gmail (figure it out)      http://web.torek.net/torek/index.html
 




 99 Posts in Topic:
[OT] lcc first experience
Morris Dovey <mrdovey@  2008-05-06 12:33:06 
Re: lcc first experience
=?ISO-8859-1?Q?Tom=E1s_=D  2008-05-06 10:41:28 
Re: lcc first experience
Morris Dovey <mrdovey@  2008-05-06 13:02:55 
Re: lcc first experience
Johannes Bauer <dfnson  2008-05-06 20:51:07 
Re: lcc first experience
=?ISO-8859-1?Q?Tom=E1s_=D  2008-05-06 15:35:32 
Re: lcc first experience
Antoninus Twink <nospa  2008-05-06 20:10:35 
Re: lcc first experience
Morris Dovey <mrdovey@  2008-05-06 13:21:40 
Re: [OT] lcc first experience
Keith Thompson <kst-u@  2008-05-06 11:19:10 
Re: lcc first experience
=?ISO-8859-1?Q?Tom=E1s_=D  2008-05-06 11:47:38 
Re: [OT] lcc first experience
Morris Dovey <mrdovey@  2008-05-06 13:49:09 
Re: lcc first experience
Paul Hsieh <websnarf@[  2008-05-07 10:52:56 
Re: lcc first experience
Eric Sosman <Eric.Sosm  2008-05-07 13:58:53 
Re: lcc first experience
dj3vande@[EMAIL PROTECTED  2008-05-07 18:41:15 
Re: lcc first experience
Spiros Bousbouras <spi  2008-05-08 11:20:03 
Re: lcc first experience
muntyan@[EMAIL PROTECTED]  2008-05-08 12:49:22 
Re: lcc first experience
roberson@[EMAIL PROTECTED  2008-05-08 20:11:47 
Re: lcc first experience
muntyan@[EMAIL PROTECTED]  2008-05-08 19:31:19 
Re: lcc first experience
Richard Heathfield <rj  2008-05-09 05:25:35 
Re: lcc first experience
jacob navia <jacob@[EM  2008-05-09 08:44:45 
Re: lcc first experience
Richard Heathfield <rj  2008-05-09 07:35:23 
Re: lcc first experience
roberson@[EMAIL PROTECTED  2008-05-09 14:59:38 
Re: lcc first experience
Nick Keighley <nick_ke  2008-05-09 01:48:41 
Re: lcc first experience
Spiros Bousbouras <spi  2008-05-08 16:17:14 
Re: lcc first experience
richard@[EMAIL PROTECTED]  2008-05-08 23:45:58 
Re: lcc first experience
Nick Keighley <nick_ke  2008-05-09 01:50:59 
Re: lcc first experience
richard@[EMAIL PROTECTED]  2008-05-09 12:00:03 
Re: lcc first experience
CBFalconer <cbfalconer  2008-05-07 17:48:52 
Re: lcc first experience
cri@[EMAIL PROTECTED] (R  2008-05-08 02:30:57 
Re: lcc first experience
CBFalconer <cbfalconer  2008-05-08 13:40:41 
Re: lcc first experience
cri@[EMAIL PROTECTED] (R  2008-05-10 04:39:47 
Re: lcc first experience
Paul Hsieh <websnarf@[  2008-05-08 09:55:08 
Re: lcc first experience
roberson@[EMAIL PROTECTED  2008-05-08 17:37:05 
Re: lcc first experience
jacob navia <jacob@[EM  2008-05-08 19:42:31 
Re: lcc first experience
roberson@[EMAIL PROTECTED  2008-05-08 18:28:31 
Re: lcc first experience
Keith Thompson <kst-u@  2008-05-08 11:55:57 
Re: lcc first experience
muntyan@[EMAIL PROTECTED]  2008-05-08 15:13:58 
Re: lcc first experience
roberson@[EMAIL PROTECTED  2008-05-09 02:07:23 
Re: lcc first experience
Paul Hsieh <websnarf@[  2008-05-08 13:24:45 
Re: lcc first experience
Eric Sosman <Eric.Sosm  2008-05-08 17:20:45 
Re: lcc first experience
jacob navia <jacob@[EM  2008-05-09 07:43:41 
Re: lcc first experience
Richard Heathfield <rj  2008-05-09 05:54:58 
Re: lcc first experience
roberson@[EMAIL PROTECTED  2008-05-09 03:31:44 
Re: lcc first experience
richard@[EMAIL PROTECTED]  2008-05-08 21:02:02 
Re: lcc first experience
richard@[EMAIL PROTECTED]  2008-05-08 21:08:29 
Re: lcc first experience
Keith Thompson <kst-u@  2008-05-08 15:15:32 
Re: lcc first experience
CBFalconer <cbfalconer  2008-05-08 19:04:25 
Re: lcc first experience
Keith Thompson <kst-u@  2008-05-08 22:40:25 
Re: lcc first experience
vippstar@[EMAIL PROTECTED  2008-05-08 14:44:50 
Re: lcc first experience
Spiros Bousbouras <spi  2008-05-08 16:09:33 
Re: lcc first experience
Eric Sosman <esosman@[  2008-05-08 21:14:14 
Re: lcc first experience
Nick Keighley <nick_ke  2008-05-09 01:19:55 
Re: [OT] lcc first experience
jacob navia <jacob@[EM  2008-05-06 20:26:59 
Re: [OT] lcc first experience
"Malcolm McLean"  2008-05-06 21:48:31 
Re: [OT] lcc first experience
nembo kid <user@[EMAIL  2008-05-07 17:51:45 
Re: [OT] lcc first experience
roberson@[EMAIL PROTECTED  2008-05-07 16:03:30 
Re: lcc first experience
vippstar@[EMAIL PROTECTED  2008-05-07 09:24:27 
Re: [OT] lcc first experience
Morris Dovey <mrdovey@  2008-05-07 12:06:24 
Re: [OT] lcc first experience
Joe Wright <joewwright  2008-05-07 16:28:29 
Re: lcc first experience
Bart <bc@[EMAIL PROTEC  2008-05-07 13:59:16 
Re: lcc first experience
jacob navia <jacob@[EM  2008-05-08 00:55:56 
Re: lcc first experience
Eric Sosman <esosman@[  2008-05-07 20:32:37 
Re: lcc first experience
Keith Thompson <kst-u@  2008-05-07 18:26:14 
binary literals (was Re: lcc first experience)
Chris Torek <nospam@[E  2008-05-08 02:18:14 
Re: lcc first experience
"Dik T. Winter"  2008-05-08 10:12:38 
Re: lcc first experience
richard@[EMAIL PROTECTED]  2008-05-08 10:36:25 
Re: lcc first experience
CBFalconer <cbfalconer  2008-05-07 20:26:31 
Re: binary literals (was Re: lcc first experience)
Ben Bacarisse <ben.use  2008-05-08 12:14:32 
Re: [OT] lcc first experience
rlb@[EMAIL PROTECTED] (R  2008-05-08 06:29:24 
Re: [OT] lcc first experience
CBFalconer <cbfalconer  2008-05-08 13:45:24 
Re: [OT] lcc first experience
rlb@[EMAIL PROTECTED] (R  2008-05-16 10:37:27 
Re: lcc first experience
Spiros Bousbouras <spi  2008-05-09 11:42:36 
Re: lcc first experience
Spiros Bousbouras <spi  2008-05-09 11:53:06 
Re: lcc first experience
Old Wolf <oldwolf@[EMA  2008-05-11 16:03:04 
Re: lcc first experience
Antoninus Twink <nospa  2008-05-09 11:42:57 
Re: [OT] lcc first experience
Harald van =?UTF-8?b?RMSz  2008-05-09 18:34:51 
Re: [OT] lcc first experience
jacob navia <jacob@[EM  2008-05-09 19:23:54 
Re: [OT] lcc first experience
Morris Dovey <mrdovey@  2008-05-09 12:29:04 
Re: [OT] lcc first experience
jacob navia <jacob@[EM  2008-05-09 20:03:18 
Re: [OT] lcc first experience
Morris Dovey <mrdovey@  2008-05-09 13:58:26 
Re: [OT] lcc first experience
rlb@[EMAIL PROTECTED] (R  2008-05-16 10:38:37 
Re: [OT] lcc first experience
Eric Sosman <esosman@[  2008-05-09 13:39:04 
Re: [OT] lcc first experience
jacob navia <jacob@[EM  2008-05-09 19:59:38 
Re: [OT] lcc first experience
Eric Sosman <esosman@[  2008-05-09 17:10:52 
Re: [OT] lcc first experience
Eric Sosman <esosman@[  2008-05-10 17:04:50 
Re: [OT] lcc first experience
Richard Heathfield <rj  2008-05-09 17:51:42 
Re: [OT] lcc first experience
jacob navia <jacob@[EM  2008-05-09 19:56:19 
Re: [OT] lcc first experience
Flash Gordon <spam@[EM  2008-05-09 19:33:22 
Re: [OT] lcc first experience
Keith Thompson <kst-u@  2008-05-09 13:03:38 
Re: [OT] lcc first experience
Flash Gordon <spam@[EM  2008-05-09 18:27:59 
Re: [OT] lcc first experience
Harald van =?UTF-8?b?RMSz  2008-05-09 20:25:29 
Re: lcc first experience
Harald van =?UTF-8?b?RMSz  2008-05-09 20:52:51 
Re: lcc first experience
Antoninus Twink <nospa  2008-05-09 20:55:58 
Re: lcc first experience
"Malcolm McLean"  2008-05-11 10:09:21 
Re: lcc first experience
Harald van =?UTF-8?b?RMSz  2008-05-09 21:06:34 
Re: [OT] lcc first experience
CBFalconer <cbfalconer  2008-05-09 16:53:05 
Re: [OT] lcc first experience
Antoninus Twink <nospa  2008-05-09 23:41:13 
Re: [OT] lcc first experience
Harald van =?UTF-8?b?RMSz  2008-05-09 23:50:09 
Re: [OT] lcc first experience
Ben Bacarisse <ben.use  2008-05-10 03:28:11 
Re: [OT] lcc first experience
Antoninus Twink <nospa  2008-05-10 23:32:59 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 16:05:33 CDT 2008.