Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 739099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:21:40+00:00 2026-05-14T08:21:40+00:00

I know how bitwise AND works,but I don’t understand how does (sourceDragMask & NSDragOperationGeneric)

  • 0

I know how bitwise AND works,but I don’t understand how does (sourceDragMask & NSDragOperationGeneric) work here,I don’t get the point.Is there anyone can explain to me?Thanks a lot.

- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
{
    NSPasteboard *pboard;
    NSDragOperation sourceDragMask;

    sourceDragMask = [sender draggingSourceOperationMask];
    pboard = [sender draggingPasteboard];

    if ( [[pboard types] containsObject:NSColorPboardType] )
    {
        if (sourceDragMask & NSDragOperationGeneric)
        {
            return NSDragOperationGeneric;
        }
    }

    return NSDragOperationNone;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T08:21:41+00:00Added an answer on May 14, 2026 at 8:21 am

    I know how bitwise AND works,but I don’t understand how does (sourceDragMask & NSDragOperationGeneric) work here,I don’t get the point.

    NSDragOperationGeneric is most likely a power of two, which means it has only one bit set. This is deliberate: Bit masks are almost all defined as powers of two (single bits) to enable bit-mask operations like this one.

    The bitwise-AND operation, as you know, evaluates to only those bits that are set in both sides. If one side has only one bit (NSDragOperationGeneric) set, then the operation effectively tests whether that bit is set in the other side.

    That’s the point of the operation: To test whether the NSDragOperationGeneric bit is set.

    There is one gotcha: As you know, a successful bitwise AND test will evaluate to the tested-for bit mask, not 1. So, for example, if you test for a bit mask that’s defined as 0x100 (1 followed by 8 clear bits), then assign that result to a BOOL (which is a signed char) variable, you’ll assign zero to the variable! This is why you sometimes see code like this:

    BOOL supportsCopyOperation = ((dragOperations & NSDragOperationCopy) == NSDragOperationCopy);
    

    or this:

    BOOL supportsCopyOperation = ((dragOperations & NSDragOperationCopy) != 0);
    

    or this:

    BOOL supportsCopyOperation = !!(dragOperations & NSDragOperationCopy);
    

    Other bit-mask operations include bitwise-OR (|) to set bits in a value (return NSDragOperationCopy | NSDragOperationMove;, for example) and bitwise-NOT (~, a.k.a. two’s complement) to invert the bits of a value, usually for “anything but” tests.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know there is a registry key indicating the install directory, but I don't
I know I must be missing something, but in a while statement how does
I have a problem while using bitwise in javascript. I don't know if I'm
I know this might be a no-brainer, but please read on. I also know
I know, I would have thought the answer was obviously no as well, but
I know its probably possible, but is it practical and doable to try and
I know its probably possible, but is it practical and doable to try and
I need to solve the following question which i can't get to work by
I am porting some Java code to Objective C and know enough bitwise to
As part of a complex aggregate I want to know the bitwise sum of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.