the algorithm of decimal<->binary conversion

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael Mair

    #16
    Re: the algorithm of decimal&lt;-&gt;binary conversion



    Mars wrote:[color=blue]
    > Peter Nilsson mentioned:
    >[color=green]
    >> Peter Nilsson wrote:
    >>[/color]
    >
    > And what's that "1u" mean in your program??
    >
    > e.g.
    > q2=(1u<<(q4-1)<<1)-1;[/color]

    You were not there when they were talking about constants...

    1 (int)
    1u, 1U (unsigned int)
    1l, 1L (long)
    1UL, 1ul, 1LU, 1lu ....
    1.0 (double)
    1.0F,1.0f (float)
    1.0L,1.0l (long double)


    -Michael
    --
    E-Mail: Mine is a gmx dot de address.

    Comment

    • Chris Williams

      #17
      Re: the algorithm of decimal&lt;-&gt;binary conversion

      Flash Gordon wrote:[color=blue]
      > Chris Williams wrote:[color=green]
      > > 2 >> 1 = 1 //division by two
      > > 4 >> 1 = 2
      > > 6 >> 1 = 3
      > > 8 >> 1 = 4
      > > 8 >> 2 = 2 //division by four
      > >
      > > 1 & 1 = 1 //modulus of 2
      > > 2 & 1 = 0
      > > 3 & 1 = 1
      > > 4 & 1 = 0
      > > 4 & 2 = 0 //modulus of 4[/color]
      >
      > Any decent optimising compiler will do this optimisation when dealing[/color]
      [color=blue]
      > with division by a constant. So it is generally better to write what[/color]
      you[color=blue]
      > mean rather than making the code harder to read.[/color]

      True. It's a two second test, but indeed there might be no change if
      your compiler was spitting your code out using shifts and ands in
      secret.

      Though I was never big on trusting the compiler to do anything past
      predetermining all math between constants--e.g. time = y + 1000 * 60;
      -> time = y + 60000; Just the general idea that between knowing how to
      do it myself or having the best optimizing compiler, I'd rather know
      what I'm doing. Though I would want one for any large project to deal
      with the 99% of code that won't be used intensively.

      -Chris

      Comment

      Working...