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. Cool bitwise trick page

Cool bitwise trick page

Scheduled Pinned Locked Moved The Weird and The Wonderful
htmlgraphicstutorial
3 Posts 3 Posters 0 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.
  • L Offline
    L Offline
    Lutoslaw
    wrote on last edited by
    #1

    Bit hacks[^] For example: Round up to the next highest power of 2:

    unsigned int v; // compute the next highest power of 2 of 32-bit v

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

    This makes my previous code soooo lame (Math.Pow(2,Math.Log(v,2)+1)) or sth like this).

    Greetings - Jacek

    L 1 Reply Last reply
    0
    • L Lutoslaw

      Bit hacks[^] For example: Round up to the next highest power of 2:

      unsigned int v; // compute the next highest power of 2 of 32-bit v

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

      This makes my previous code soooo lame (Math.Pow(2,Math.Log(v,2)+1)) or sth like this).

      Greetings - Jacek

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

      It's a good reference, but on the average day (ok no, but often enough) I also need one of the various mirrors/rotates on a 64bit int as 8x8 matrix (that site is also a good reference).

      R 1 Reply Last reply
      0
      • L Lost User

        It's a good reference, but on the average day (ok no, but often enough) I also need one of the various mirrors/rotates on a 64bit int as 8x8 matrix (that site is also a good reference).

        R Offline
        R Offline
        Rajesh Anuhya
        wrote on last edited by
        #3

        +5,, Thanks for the link

        My Tip/Trick[^]

        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