Results 1 to 5 of 5

Thread: Set sixth bit to 1

  1. #1
    Junior Member
    Join Date
    Nov 2007
    Answers
    2

    Set sixth bit to 1

    Given a sixteen bit number. How can sixth bit can be set to 1 irrespective of its initial value and sixth bit reset to zero irrespective of its initial value


  2. #2
    Junior Member
    Join Date
    Nov 2007
    Answers
    2

    Re: Set sixth bit to 1

    suppose 'a' contains 16 bit number. And initialize b with 32.

    a=a|b; /*this will convert 6th bit to One irrespective of its original bit*/

    now for making 6th bit 0, load b with 65503 and do the following.
    a=a&b;


  3. #3
    Junior Member
    Join Date
    Dec 2007
    Answers
    1

    Arrow Re: Set sixth bit to 1

    for setting the 6th bit:
    x | (1<<5)

    for unsetting the 6th bit:
    x & (~(1<<5))

    hope it helps.



  4. #4
    Contributing Member
    Join Date
    Dec 2007
    Answers
    46

    Re: Set sixth bit to 1

    Quote Originally Posted by dattu.kv View Post
    Given a sixteen bit number. How can sixth bit can be set to 1 irrespective of its initial value and sixth bit reset to zero irrespective of its initial value
    You could also use the OR and AND operators to help you put.

    #define MASK1 0x0040 // Note that 6th bit is 1, counting from 0
    #define MASK2 0xffbf // Note that the 6th bit is 0

    // Set 6th bit of x to 1
    x = x | MASK1

    // Set 6th bit of x to 0
    x = x & MASK2


  5. #5
    Junior Member
    Join Date
    Jan 2008
    Answers
    1

    Re: Set sixth bit to 1

    what the hell is the answr..


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact