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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:06:04+00:00 2026-05-29T04:06:04+00:00

I have to create a function bitParity(int x) that takes an integer and returns

  • 0

I have to create a function bitParity(int x) that takes an integer and returns 1 if there is an odd number of 0‘s in the bit form of x, and 0 otherwise.

Ex: bitParity(5) = 0, bitParity(7) = 1

However, this is difficult as I can only use bit operators on this problem (! ˜ & ˆ | + << >> are the only legal ones). That means, no loops, if-then, or anything of the sort. Constants can be used.

So far, what I have doesn’t work, but I figured that I should shift the bits of the integer 16, 8, and 4 times and XOR the remaining integers.

Can anyone offer some advice? Thanks.

  • 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-29T04:06:04+00:00Added an answer on May 29, 2026 at 4:06 am

    This is properly solved with a loop. But here is a way to do it without.

    x = (x & 0x0000FFFF) ^ (x >> 16)
    x = (x & 0x000000FF) ^ (x >> 8)
    x = (x & 0x0000000F) ^ (x >> 4)
    x = (x & 0x00000003) ^ (x >> 2)
    x = (x & 0x00000001) ^ (x >> 1)
    

    Edit: I don’t need the &. A better version:

    x ^= x >> 16
    x ^= x >> 8
    x ^= x >> 4
    x ^= x >> 2
    x ^= x >> 1
    x &= 1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this script: CREATE FUNCTION dbo.CheckIfSFExists(@param1 INT, @param2 BIT = 1 ) RETURNS
I have the following function: CREATE FUNCTION fGetTransactionStatusLog ( @TransactionID int ) RETURNS varchar(8000)
How do I create a Ruby function that does not have an explicit number
I have the following function CREATE FUNCTION GetIdentity() RETURNS INT AS BEGIN RETURN (IDENT_CURRENT('tblTempPo'))
i have created a function: CREATE FUNCTION FindDistrictId (@param XML) RETURNS INT (...) which
I have something like this create function Answers_Index(@id int, @questionID int) returns int as
I have a function that returns groups(clusters) from a table.. create function dbo.ftAllClusters() returns
I have three classes that all have a static function called 'create'. I would
Does anyone have a working class or function to create the hashed email that
I have function CREATE OR REPLACE FUNCTION public.GetSoilCod ( cod1 integer = 0, cod2

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.