Re: binary number

From: Mike Wahler (mkwahler_at_mkwahler.net)
Date: 09/02/04


Date: Wed, 01 Sep 2004 23:22:24 GMT


"Kai-Uwe Bux" <jkherciueh@gmx.net> wrote in message
news:ch5ea1$6t7$1@murdoch.acc.Virginia.EDU...
> Mike Wahler wrote:
>
> >
> > "red floyd" <no.spam@here.dude> wrote in message
> > news:KWmZc.14518$AX6.13446@newssvr29.news.prodigy.com...
> >> Risto Lankinen wrote:
> >> >
> >> > [By the way, C and C++ are perhaps the only programming languages
> >> > having no token representing decimal zero! :-]
> >> >
> >> > - Risto -
> >> >
> >> >
> >>
> >> what would the token 0 be, then?
> >
> > Octal zero. (it begins with the '0' character).
> >
> >
> >
> > -Mike
>
> I am confused?

Perhaps.

> What exactly is the difference between the numerical constant 0_8 denoted

0_8 is not a numerical constant. It's not a valid C++ token at all.

> by the string "0"

A string is not a numeric literal, it's a string literal.

> in octal notation

In C++, octal notation is expressed by the first digit being zero.

>versus the numerical constant 0_10.

0_10 is not a numerical constant. It's not a valid C++ token at all.

> denoted by the string "0"

A string is not a numeric literal, it's a string literal.

> is decimal notation

In C++, decimal notation is expressed by the first digit being
1, 2, 3, 4, 5, 6, 7, 8, or 9

>(as existent in other
> languages).

This is C++, not other languages.

>In particular, what is
>
> 0_8 - 0_10

>From a C++ perspective, it's gibberish.

>From the C++ standard:

================= begin quote ================
  ISO/IEC 14882:1998(E)

  2.13.1 Integer literals

       integer­-literal:
                    decimal­-literal integer­-suffix opt
                    octal­-literal integer­-suffix opt
                    hexadecimal-­literal integer­-suffix opt

       decimal-­literal:
                    nonzero-­digit
                    decimal-­literal digit

       octal­-literal:
                    0
                    octal­-literal octal­-digit

       hexadecimal­-literal:
                    0x hexadecimal-­digit
                    0X hexadecimal-­digit
                    hexadecimal-­literal hexadecimal-­digit

       nonzero­-digit: one of
                    1 2 3 4 5 6 7 8 9

       octal-­digit: one of
                    0 1 2 3 4 5 6 7

       hexadecimal­-digit: one of
                    0 1 2 3 4 5 6 7 8 9
                    a b c d e f
                    A B C D E F

       integer-­suffix:
                    unsigned­-suffix long­s-uffix opt
                    long­-suffix unsigned­-suffix opt

       unsigned-­suffix: one of
                    u U

       long­-suffix: one of
                    l L

1 An integer literal is a sequence of digits that has no period
  or exponent part. An integer literal may have a prefix that
  specifies its base and a suffix that specifies its type. The
  lexically first digit of the sequence of digits is the most
  significant. A decimal integer literal (base ten) begins with
  a digit other than 0 and consists of a sequence of decimal
  digits. An octal integer literal (base eight) begins with the
  digit 0 and consists of a sequence of octal digits. (22)
  A hexadecimal integer literal (base sixteen) begins with 0x
  or 0X and consists of a sequence of hexadecimal digits, which
  include the decimal digits and the letters a through f and A
  through F with decimal values ten through fifteen. [Example:
  the number twelve can be written 12, 014, or 0XC. ]

2 The type of an integer literal depends on its form, value, and
  suffix. If it is decimal and has no suffix, it has the first of
  these types in which its value can be represented: int, long int;
  if the value cannot be represented as a long int, the behavior
  is undefined. If it is octal or hexadecimal and has no suffix,
  it has the first of these types in which its value can be
  represented: int, unsigned int, long int, unsigned long int.
  If it is suffixed by u or U, its type is the first of these
  types in which its value can be represented: unsigned int,
  unsigned long int. If it is suffixed by l or L, its type is the
  first of these types in which its value can be represented: long
  int, unsigned long int. If it is suffixed by ul, lu, uL, Lu, Ul,
  lU, UL, or LU, its type is unsigned long int. 3 A program is
  ill­formed if one of its translation units contains an integer
  literal that cannot be represented by any of the allowed types.

  (21) The term "literal" generally designates, in this International
       Standard, those tokens that are called "constants" in ISO C.

  (22) The digits 8 and 9 are not octal digits.
================= end quote ==================

The base of literal 0 doesn't really matter, since zero is zero,
whatever the base.

-Mike



Relevant Pages

  • Re: System.Math.Round bug (repost)
    ... Round(double value, int digits) ... It always seems to use the Round(decimal value, int decimals) version, no ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: help me
    ... to exponential...if i use int then its not accepting more than 4 ... I think you've misunderstood your assignment. ... If you want the whole entry (17 digits) into *one* variable, ... This means that it's sufficient with an array of int's (even with bytes, ...
    (comp.lang.java.help)
  • Re: Integer subtraction problem, help!
    ... > Since that won't fit into an int, ... C has no negative integer literals, ... If you're assuming a 32-bit 2's-complement representation for int, ...
    (comp.lang.c)
  • Re: algorithm for brute force an variable lenght array
    ... (chromossomeint will range from 0 to 4) ... In an odometer, there are a series of wheels that count up from 0 ... digits ... OVERFLOW if the odometer overflows, ...
    (comp.lang.c)
  • Re: String Vergleich Hausnummer
    ... public int compareTo{ ... int cmp = digits - other.digits; ... for (Hausnummer nr: list) System.out.print; ...
    (de.comp.lang.java)