Thread: how to set bit X of Y to 1?

  1. #1
    evader
    Guest

    Question how to set bit X of Y to 1?

    I think x&=~(1<<y) would set bit # y to 0 but I cant figure out how to set it to 1. I tried things like x&=(1<<y) but it sets all of x to 1 and not only the bit that I need.
    Anyone know the correct algorith?

  2. #2
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    Try x|=(1<<y).
    zen

  3. #3
    evader
    Guest

    Exclamation

    Thanks, it works. I was trying to fix that problem for 15 hours a day for 3 days and I was loosing all hope for making my program work.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. bit operation question
    By mr_coffee in forum C Programming
    Replies: 3
    Last Post: 04-07-2009, 05:00 PM
  2. set a flag in a bit stream
    By sarathius in forum C Programming
    Replies: 2
    Last Post: 02-06-2008, 04:25 AM
  3. Find all possible subset of a given set
    By Downnin in forum C++ Programming
    Replies: 7
    Last Post: 11-09-2005, 02:03 PM
  4. "if you love someone" :D
    By Carlos in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 10-02-2003, 01:10 AM
  5. problem with open gl engine.
    By gell10 in forum Game Programming
    Replies: 1
    Last Post: 08-21-2003, 04:10 AM