Question: Write code to implement the following function: /* Return 1 when any odd bit of x equals 1; 0 otherwise. Assume w=32. */ int any_odd_one(unsigned

Write code to implement the following function: /* Return 1 when any odd bit of x equals 1; 0 otherwise. Assume w=32. */ int any_odd_one(unsigned x)

This is C code. I just want to understand this code clearly. Specifically when copmaring the bits with the and opperator. 

#include

 

int any_odd_one(unsigned x)

{

    return (x & 0x55555555) && 1;       <------------------------ Can you explain what is going on here?

}

 

int main()

{

    unsigned j;

 

    printf("Enter integer ");

    scanf("%u",&j);

 

    printf("%d",any_odd_one(j));

}

Step by Step Solution

3.49 Rating (172 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

find... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Document Format (2 attachments)

PDF file Icon

635f619f3cb30_231895.pdf

180 KBs PDF File

Word file Icon

635f619f3cb30_231895.docx

120 KBs Word File

Students Have Also Explored These Related Accounting Questions!