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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:54:02+00:00 2026-05-31T17:54:02+00:00

I am calculating XOR of two short integers using XOR ^ operator in a

  • 0

I am calculating XOR of two short integers using XOR ^ operator in a traditional fashion. Below is the method-

short a=197;
short b=341;
short y = (short) (a ^ b);

However the XOR always returned integer but in my case inputs are short integer, that is why i am casting short to the XOR output. The XOR can be calculated in different manners (example: using BigInteger etc.) but performance wise (less time) which is the best for short integers? While keeping performance in mind, should i first convert each short integer to binary number using Integer.toBinaryString(number) then apply bitwise XOR?

  • 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-31T17:54:03+00:00Added an answer on May 31, 2026 at 5:54 pm
    short s1 = ...
    short s2 = ...
    short result = (short) (s1 ^ s2);
    

    This is the most efficient way to XOR two shorts together. It does not run into the overhead of creating BigIntegers and the cast will never cause an overflow issue as both s1 and s2 are shorts to begin with.

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

Sidebar

Related Questions

Here i am using two different functions for calculating CRC16 for any type of
Calculating the area of a simple irregular polygon is trivial . However, consider the
I am calculating the gradient of grayscale images using OpenCV, the resulting values for
I’m calculating the inactive interval of a particular user using the following code: inActiveInterval
I am calculating the correlation of two arrays. x = {1,2,3}; y = {1,1,1};
Just calculating sum of two arrays with slight modification in code int main() {
I am calculating the number of days between two dates(the 2 dates are in
I'm calculating the distance between two GeoCoordinates. I'm testing my app against 3-4 other
I have a problem calculating the distance between two geopoints. The geopoints are: position1
I am calculating current time Interval using following codes: NSTimeInterval tInt=[[NSDate date] timeIntervalSince1970]; int

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.