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. Other Discussions
  3. The Weird and The Wonderful
  4. The mystery function

The mystery function

Scheduled Pinned Locked Moved The Weird and The Wonderful
game-devquestion
5 Posts 4 Posters 6 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.
  • P Offline
    P Offline
    Pascal Ganaye
    wrote on last edited by
    #1

    This is a little game. Someone in CodeProject wrote this: I'll let you guess what this does and how it should be named:

    static int f(int v)
    {
    unchecked
    {

        v--;
        v |= v >> 1;
        v |= v >> 2;
        v |= v >> 4;
        v |= v >> 8;
        v |= v >> 16;
        v++;
    }
    return v;
    

    }

    For the record when I posted this I promise did not realize that previous post was speaking about the exact same thing. How extraordinary is this?

    N S L 3 Replies Last reply
    0
    • P Pascal Ganaye

      This is a little game. Someone in CodeProject wrote this: I'll let you guess what this does and how it should be named:

      static int f(int v)
      {
      unchecked
      {

          v--;
          v |= v >> 1;
          v |= v >> 2;
          v |= v >> 4;
          v |= v >> 8;
          v |= v >> 16;
          v++;
      }
      return v;
      

      }

      For the record when I posted this I promise did not realize that previous post was speaking about the exact same thing. How extraordinary is this?

      N Offline
      N Offline
      Nagy Vilmos
      wrote on last edited by
      #2

      Pascal Ganaye wrote:

      guess what this does

      Checks if Leslie Nielsen is dead or not?


      Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

      1 Reply Last reply
      0
      • P Pascal Ganaye

        This is a little game. Someone in CodeProject wrote this: I'll let you guess what this does and how it should be named:

        static int f(int v)
        {
        unchecked
        {

            v--;
            v |= v >> 1;
            v |= v >> 2;
            v |= v >> 4;
            v |= v >> 8;
            v |= v >> 16;
            v++;
        }
        return v;
        

        }

        For the record when I posted this I promise did not realize that previous post was speaking about the exact same thing. How extraordinary is this?

        S Offline
        S Offline
        Sentenryu
        wrote on last edited by
        #3

        Round up to the next highest power of 2, written by Jacek Gajek, in the message bellow. yes, i'm not funny

        1 Reply Last reply
        0
        • P Pascal Ganaye

          This is a little game. Someone in CodeProject wrote this: I'll let you guess what this does and how it should be named:

          static int f(int v)
          {
          unchecked
          {

              v--;
              v |= v >> 1;
              v |= v >> 2;
              v |= v >> 4;
              v |= v >> 8;
              v |= v >> 16;
              v++;
          }
          return v;
          

          }

          For the record when I posted this I promise did not realize that previous post was speaking about the exact same thing. How extraordinary is this?

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          You should probably have waited until it wasn't the previous thread anymore :)

          P 1 Reply Last reply
          0
          • L Lost User

            You should probably have waited until it wasn't the previous thread anymore :)

            P Offline
            P Offline
            Pascal Ganaye
            wrote on last edited by
            #5

            I can't really believe it. I found this code in a string library I had downloaded from code project a few days before. I had not read the previous post. What are the odds? This is spooky.

            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