Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Another programming puzzle

Another programming puzzle

Scheduled Pinned Locked Moved The Lounge
c++question
10 Posts 5 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Corky
    wrote on last edited by
    #1

    What is this bit of code dong.

    long stuff(long n1,long n)
    {
    long a;
    long c = 0;
    long d = (2 * (n1/2));
    for (a = 1; d - a > 0;a *= 2)
    c++;
    a = _lrotl(n,c);
    if(n1 - d)
    a += n;
    return a;
    }

    No fare compiling it. ;) This Sig For Rent
    Corky

    _ B L 4 Replies Last reply
    0
    • C Corky

      What is this bit of code dong.

      long stuff(long n1,long n)
      {
      long a;
      long c = 0;
      long d = (2 * (n1/2));
      for (a = 1; d - a > 0;a *= 2)
      c++;
      a = _lrotl(n,c);
      if(n1 - d)
      a += n;
      return a;
      }

      No fare compiling it. ;) This Sig For Rent
      Corky

      _ Offline
      _ Offline
      _Magnus_
      wrote on last edited by
      #2

      Is it the Linux kernel?? /Magnus

      B 1 Reply Last reply
      0
      • _ _Magnus_

        Is it the Linux kernel?? /Magnus

        B Offline
        B Offline
        Brian Delahunty
        wrote on last edited by
        #3

        Magnus H wrote: Is it the Linux kernel?? You one of these, "I hate Linux" people?


        :~ (-_-) :~

        _ 1 Reply Last reply
        0
        • B Brian Delahunty

          Magnus H wrote: Is it the Linux kernel?? You one of these, "I hate Linux" people?


          :~ (-_-) :~

          _ Offline
          _ Offline
          _Magnus_
          wrote on last edited by
          #4

          No, dont have any opinion at all about since i never used it. :wtf: (just because it looks so cool ) /Magnus

          B 1 Reply Last reply
          0
          • _ _Magnus_

            No, dont have any opinion at all about since i never used it. :wtf: (just because it looks so cool ) /Magnus

            B Offline
            B Offline
            Brian Delahunty
            wrote on last edited by
            #5

            Magnus H wrote: :wtf: (just because it looks so cool ) lol... :rolleyes: is cool too


            :~ (-_-) :~

            1 Reply Last reply
            0
            • C Corky

              What is this bit of code dong.

              long stuff(long n1,long n)
              {
              long a;
              long c = 0;
              long d = (2 * (n1/2));
              for (a = 1; d - a > 0;a *= 2)
              c++;
              a = _lrotl(n,c);
              if(n1 - d)
              a += n;
              return a;
              }

              No fare compiling it. ;) This Sig For Rent
              Corky

              B Offline
              B Offline
              Brigg Thorp
              wrote on last edited by
              #6

              I think this is changing from little endian to big endian. Am I right??? Brigg Thorp Software Engineer Timex Corporation

              1 Reply Last reply
              0
              • C Corky

                What is this bit of code dong.

                long stuff(long n1,long n)
                {
                long a;
                long c = 0;
                long d = (2 * (n1/2));
                for (a = 1; d - a > 0;a *= 2)
                c++;
                a = _lrotl(n,c);
                if(n1 - d)
                a += n;
                return a;
                }

                No fare compiling it. ;) This Sig For Rent
                Corky

                L Offline
                L Offline
                lucy 0
                wrote on last edited by
                #7

                I don't know how to express it in English. But I think what the program is trying to do is: to multiply n by a factor K, where K is 2^nll if nl is even Or a = n* (2^nll + 1) if nl is odd. nll is determined by nl. For example, if nl = 9, then nll = 3, in that 2^4 > 9 > 2^3. If nl = 16, then nll = 4, where 16 = 2^4. The for loop is to get the nll based on nl. Is my guess right? (what a hell is my English. :-()

                C 1 Reply Last reply
                0
                • C Corky

                  What is this bit of code dong.

                  long stuff(long n1,long n)
                  {
                  long a;
                  long c = 0;
                  long d = (2 * (n1/2));
                  for (a = 1; d - a > 0;a *= 2)
                  c++;
                  a = _lrotl(n,c);
                  if(n1 - d)
                  a += n;
                  return a;
                  }

                  No fare compiling it. ;) This Sig For Rent
                  Corky

                  _ Offline
                  _ Offline
                  _Magnus_
                  wrote on last edited by
                  #8

                  I think i should post some of my own code as a puzzle, then maybe i finally can find out what it actually does. :) /Magnus

                  B 1 Reply Last reply
                  0
                  • _ _Magnus_

                    I think i should post some of my own code as a puzzle, then maybe i finally can find out what it actually does. :) /Magnus

                    B Offline
                    B Offline
                    Brian Delahunty
                    wrote on last edited by
                    #9

                    Magnus H wrote: I think i should post some of my own code as a puzzle, then maybe i finally can find out what it actually does. LOL... yeah/ the code that I write when I'm tired normally doesn't make any sense the next day. I think your is a good idea.


                    :~ (-_-) :~

                    1 Reply Last reply
                    0
                    • L lucy 0

                      I don't know how to express it in English. But I think what the program is trying to do is: to multiply n by a factor K, where K is 2^nll if nl is even Or a = n* (2^nll + 1) if nl is odd. nll is determined by nl. For example, if nl = 9, then nll = 3, in that 2^4 > 9 > 2^3. If nl = 16, then nll = 4, where 16 = 2^4. The for loop is to get the nll based on nl. Is my guess right? (what a hell is my English. :-()

                      C Offline
                      C Offline
                      Corky
                      wrote on last edited by
                      #10

                      It's just basic multiplication (n * n1), done one of the ways the CPU does it the other way is to add n to itself n1 times (for (int i = 0; i < nl; i++) a += n; )). This Sig For Rent
                      Corky

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups