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

  • SEARCH
  • Home
  • 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 904989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:08:29+00:00 2026-05-15T16:08:29+00:00

I have 4 numbers 0-3 which is an enum (objective-c) and I’d like to

  • 0

I have 4 numbers 0-3 which is an enum (objective-c) and I’d like to get the opposite using a formula. So if 0 is put into the formula it returns 2 and if it 2 is entered then it returns 0 (and same with 1 and 3).

The reason being (and it is programming related) that I want to get the opposite of an enum without having to do an if or switch statement. But this means that any formula (if it is possible must uncomplex, so that it is more efficient than using if or switch.

  • 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-15T16:08:29+00:00Added an answer on May 15, 2026 at 4:08 pm

    The formula is very simple:

    n = n ^ 2;
    

    The bitvalues of 0 – 3 and how an exclusive or changes them:

    n       ^10
    ---------------
    0 = 00 : 10 = 2
    1 = 01 : 11 = 3
    2 = 10 : 00 = 0
    3 = 11 : 01 = 1
    

    Test (written in C#):

    for (int n = 0; n <= 3; n++) {
      Console.WriteLine("{0} : {1}", n, n ^ 2);
    }
    

    Output:

    0 : 2
    1 : 3
    2 : 0
    3 : 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a 2 enum values representing a mapping to object which I'm (currently)
Hallo, I've added a jQuery slider and now I want to have numbers above
I'm writing porting file-io set of functions from c into a c++ class. Magic
I have two strings that I need to pull data out of but can't
i have this links: <a id = link_1 href = #>Cars</a> <a id =
1) I’m aware of the following benefits: they increase the level of abstraction since
I was wondering if there is some sort of magic I can use to
I've been working through Bjarne Stroustrup's The C++ Programming Language (2nd edition - I
My question is probably a simple one to people used to ASP.NET, So here
I'm trying to load some decimal values from a file but I can't work

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.