Topic: Why don't c/c++ have binary numbers?


Author: maxtal@physics.su.OZ.AU (John Max Skaller)
Date: Mon, 27 Jun 1994 15:37:00 GMT
Raw View
In article <Crx1sx.KEB@ennews.eas.asu.edu> sapir@enuxsa.eas.asu.edu (Yitzhak Sapir) writes:
>In article <2uabcr$8s1@cc.tut.fi>,
>>
>>and it would have been lots easier, if there was binary numbers in c.
>>and changing the shape would be easier, etc...
>>
>>Is there any reason, why binary numbers are not implemented in c as
>>hex-numbers are?

 The reason in C is historical. The reason in C++ is
that the extensions subgroup rejected my proposal for
binary literals. (For reasons I cant fathom, to me its
obviously sensible to have them).

--
        JOHN (MAX) SKALLER,         INTERNET:maxtal@suphys.physics.su.oz.au
 Maxtal Pty Ltd,      CSERVE:10236.1703
        6 MacKay St ASHFIELD,     Mem: SA IT/9/22,SC22/WG21
        NSW 2131, AUSTRALIA




Author: imp@boulder.parcplace.com (Warner Losh)
Date: Tue, 28 Jun 1994 15:48:31 GMT
Raw View
In article <2uabcr$8s1@cc.tut.fi>,
>
>and it would have been lots easier, if there was binary numbers in c.
>and changing the shape would be easier, etc...

In article <Cs2BDp.3z5@ucc.su.OZ.AU> maxtal@physics.su.OZ.AU (John Max
Skaller) writes:
> The reason in C is historical. The reason in C++ is
>that the extensions subgroup rejected my proposal for
>binary literals. (For reasons I cant fathom, to me its
>obviously sensible to have them).

I know that binary numbers were proposed and rejected to the ANSI C
committee.  The reason for rejection was that it wasn't commonly
implemented.  I think Desmet C implemented it and their people
proposed it.  I could be fuzzy on this, however, as it has been a few
years.

It would be great to say
 0b01011001
or something like that and have it do the right thing.

Warner
--
Warner Losh  imp@boulder.parcplace.COM ParcPlace Boulder
"... but I can't promote you to "Prima Donna" unless you demonstrate a few
 more serious personality disorders"




Author: bagpiper@netcom.com (Michael Hunter)
Date: Wed, 29 Jun 1994 21:27:21 GMT
Raw View
Warner Losh (imp@boulder.parcplace.com) wrote:
: In article <2uabcr$8s1@cc.tut.fi>,
: I know that binary numbers were proposed and rejected to the ANSI C
: committee.  The reason for rejection was that it wasn't commonly
: implemented.  I think Desmet C implemented it and their people
: proposed it.  I could be fuzzy on this, however, as it has been a few
: years.

Datalight C also supported binary numbers.  Does Zortech C also?

  mph
--
* Michael Hunter bagpiper@netcom.com or QUICS: mphunter




Author: jones@cais.cais.com (Ben Jones)
Date: 23 Jun 1994 15:32:01 GMT
Raw View
Pulkkinen Tero (p150650@proffa.cc.tut.fi) wrote:
: I was making a program that draws an arrow to screen.
: The easiest way to draw an arrow is with binary-numbers.
: After i noticed that there was no way i can get binary numbers
: to my c-program, i draw the whole shape to paper, and converted
: it to hex. now the code looks something like this:

: int pointer[]=   /* int= 16 bits */
: {
: 0x0000,
: 0x0100,
: 0x0300,
:   ...
: 0x0ffc,
: 0x0000
: }

: and it would have been lots easier, if there was binary numbers in c.
: and changing the shape would be easier, etc...

: Is there any reason, why binary numbers are not implemented in c as
: hex-numbers are?

A suggestion for the notation:  Use 'b' instead of 'x' for binary numbers:

    0b00010011 == 0x13

Ben Jones
jones@arsoftware.arclch.com












Author: sapir@enuxsa.eas.asu.edu (Yitzhak Sapir)
Date: Fri, 24 Jun 1994 19:22:08 GMT
Raw View
In article <2uabcr$8s1@cc.tut.fi>,
Pulkkinen Tero <p150650@proffa.cc.tut.fi> wrote:
>int pointer[]=   /* int= 16 bits */
>{
>0x0000,
>0x0100,
>0x0300,
>  ...
>0x0ffc,
>0x0000
>}
>
>and it would have been lots easier, if there was binary numbers in c.
>and changing the shape would be easier, etc...
>
>Is there any reason, why binary numbers are not implemented in c as
>hex-numbers are?
>
>-- tero pulkkinen -- p150650@proffa.cc.tut.fi --

I never considered this a problem.  While I never had a reason to use it
so far, I got an idea a while back, to implement binary numbers as
follows.  In particular, doing: BINARY(10010100,1011101) should evaluate
to the binary equivalent (0x945D).  I haven't tested it with this value,
but I tested it with some other similar value, and it worked.

[ cut here ]
#include <stdio.h>
#define BIN____(number) \
                        ( (((number / 10000000) % 2) << 7) | \
                         (((number / 1000000) % 2) << 6) | \
                         (((number / 100000) % 2) << 5) | \
                         (((number / 10000) % 2) << 4) | \
                         (((number / 1000) % 2) << 3) | \
                         (((number / 100) % 2) << 2) | \
                         (((number / 10) % 2) << 1) | \
                           (number % 2) )
#define BINARY(highbyte,lowbyte) (BIN____(highbyte) << 8 | BIN____(lowbyte))
main ()
{
    long int test1, test2;
    scanf ("%ld%ld", &test1, &test2);
    printf ("\t%X\n", (int)BINARY(test1,test2));
}






Author: p150650@proffa.cc.tut.fi (Pulkkinen Tero)
Date: 22 Jun 1994 21:44:59 GMT
Raw View
I was making a program that draws an arrow to screen.
The easiest way to draw an arrow is with binary-numbers.
After i noticed that there was no way i can get binary numbers
to my c-program, i draw the whole shape to paper, and converted
it to hex. now the code looks something like this:

int pointer[]=   /* int= 16 bits */
{
0x0000,
0x0100,
0x0300,
  ...
0x0ffc,
0x0000
}

and it would have been lots easier, if there was binary numbers in c.
and changing the shape would be easier, etc...

Is there any reason, why binary numbers are not implemented in c as
hex-numbers are?

--

-- tero pulkkinen -- p150650@proffa.cc.tut.fi --