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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:19:43+00:00 2026-05-25T03:19:43+00:00

My function takes in a 32 bit int and I need to return a

  • 0

My function takes in a 32 bit int and I need to return a 0 or 1 if that number has a 1 in any even position. I cant use any conditional statements I also can only access 8 bits at a time.

Here is an example input:
10001000 01011101 00000000 11001110

1) Shift the bits and and them with AA(10101010) and store each one in a variable.

int a = 10001000
int b = 1000
int c = 0
int d = 10001010

Now I need to return a 0 if there were no odd bits set and 1 if there were. As we can see there were. So I need to combine these into one number and then use the !! operator to return 0 or 1. This is where I am having trouble.

int valueToReturn = a | b | c | d;

Now I need to say:

return !!valueTOReturn; 

It is not return the right value can anyone give me any insight???

I cannot use any condition statements like || &&

I figured it out. Everything I said gives the right answer but I was grabbing the wrong value for one of my variables. Thanks for all the help!

  • 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-25T03:19:43+00:00Added an answer on May 25, 2026 at 3:19 am

    First of all, you’re not storing bits the way you’re thinking.

    int a = 10001000
    

    is actually 10,001,000 (which in binary, b100110001001101001101000).

    You say that the function takes in a 32-bit integer, so what you can do is extract each of the 8-bit portions like so:

    unsigned char a, b, c, d;
    a = (unsigned char)(input & 0xff);
    b = (unsigned char)((input >> 8) & 0xff);
    c = (unsigned char)((input >> 16) & 0xff);
    d = (unsigned char)((input >> 24) & 0xff);
    

    Now you can perform your masking/testing operation:

    return (0xAA & a) | (0xAA & b) | (0xAA & c) | (0xAA & d);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a function in c# that takes two 32 bit integers (int) and
I have to create a function bitParity(int x) that takes an integer and returns
I am using a library that has a function that takes an array of
I have a function that takes 24 bit to 12 bit hex and prints
My function takes an array of ifstream ofjects and the number of ifstream objects
Say a function takes a void pointer as an argument, like so: int func(void
I need to find out the time a function takes for computing the performance
In R, the plot() function takes a pch argument that controls the appearance of
Is it possible to use libxml with unicode? For example the xmlParseDoc function takes
The function below takes the argv[0] argument that contains the calling path of the

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.