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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:57:48+00:00 2026-05-24T23:57:48+00:00

So I have a bit sequence: 1010 1 is the MSB. My function needs

  • 0

So I have a bit sequence:

1010

1 is the MSB.

My function needs to return an integer of 0 if an odd bit is 0 or a 1 if its a 1.

I cannot use any for loops or anything of that nature to see if I need to return a 0 or 1. Does anyone have any suggestions how to go about this.

I was thinking about using a not operation but I can figure out how to exactly use it.

So far I am using a sequence of 1010…10 and then anding it. Doing that to the above would get me 1010. Now I need to find out if I return a 1 or a 0.

  • 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-24T23:57:49+00:00Added an answer on May 24, 2026 at 11:57 pm

    Say we’re talking about 32bit integers. I assume you want to know if ANY ODD bit is SET (1).

    To do this we create an integer that looks like this:

    10101010101010101010101010101010
    

    Now, if we AND (&) by this, all the even bits get filtered out. Now if the number is not zero one or more odd bits were set. In C:

    #include <stdint.h>
    
    int hasodd(uint32_t x) {
        // 0xAAAAAAAA = 10101010101010101010101010101010
        // double negation to turn x>0 into 1 and leave 0 alone
        return !!(x & 0xAAAAAAAA); 
    }
    

    If you meant that you should return whether the Nth bit is set, this works. It right-shifts a 1 to the correct position to filter out all the irrelevant bits:

    #include <stdint.h>
    
    int nthbitset(uint32_t x, int n) {
        return x & (1 << n);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some 256-character strings of hexadecimal characters which represent a sequence of bit
I have Clojure function that takes a sequence of numbers chops it into the
I have a bash sequence, grep integer = $1 | awk -F= '{printf(%d\n,int($2*327))}' which
More specifically: I have a sequence of 32 bit unsigned RGBA integers for pixels-
I've got a sequence of Javascript function calls in a function I have defined
i have bit of code that causes an underflow: var t1, t2, delta: DWORD:
I have this bit of javascript written with jQuery 1.2.5. It's contained inside the
I have a bit of code that basically reads an XML document using the
I have a bit of code that passes around a ton of objects and
I have a bit of a hybrid situation on my hands. I'm writing an

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.