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 87967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:29:09+00:00 2026-05-10T22:29:09+00:00

How can the XOR operation (on two 32 bit ints) be implemented using only

  • 0

How can the XOR operation (on two 32 bit ints) be implemented using only basic arithmetic operations? Do you have to do it bitwise after dividing by each power of 2 in turn, or is there a shortcut? I don’t care about execution speed so much as about the simplest, shortest code.

Edit: This is not homework, but a riddle posed on a hacker.org. The point is to implement XOR on a stack-based virtual machine with very limited operations (similar to the brainfuck language and yes – no shift or mod). Using that VM is the difficult part, though of course made easier by an algorithm that is short and simple.

While FryGuy’s solution is clever, I’ll have to go with my original ideal (similar to litb’s solution) because comparisons are difficult to use as well in that environment.

  • 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. 2026-05-10T22:29:10+00:00Added an answer on May 10, 2026 at 10:29 pm

    I’m sorry i only know the straight forward one in head:

    uint32_t mod_op(uint32_t a, uint32_t b) {     uint32_t int_div = a / b;     return a - (b * int_div); }  uint32_t xor_op(uint32_t a, uint32_t b) {     uint32_t n = 1u;     uint32_t result = 0u;     while(a != 0 || b != 0) {         // or just: result += n * mod_op(a - b, 2);         if(mod_op(a, 2) != mod_op(b, 2)) {             result += n;         }         a /= 2;         b /= 2;         n *= 2;     }     return result; } 

    The alternative in comments can be used instead of the if to avoid branching. But then again, the solution isn’t exactly fast either and it makes it look stranger 🙂

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

Sidebar

Ask A Question

Stats

  • Questions 122k
  • Answers 122k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer After a while I finally got it. I ended up… May 12, 2026 at 12:45 am
  • Editorial Team
    Editorial Team added an answer Some links that may be of interest (found by searching):… May 12, 2026 at 12:45 am
  • Editorial Team
    Editorial Team added an answer You don't need to use PHP, MySQL has a function… May 12, 2026 at 12:45 am

Related Questions

I am looking for a way to uniformly choose values in GF(2^M) between two
I was going to ask a question here about whether or not my design
Observations: Java has a logical AND operator. Java has a logical OR operator. Java
i have a problem related to the design of a composite structure. I have

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.