problems with function

How to write a function invert(x,p,n) that returnsx with n bits that begin at position p inverted ( i.e. chaged 1into 0 and vice versa) livig the others unchanged
Who is Participating?
LucHoltkampConnect With a Mentor Commented:
unsigned inverse(unsigned x, unsigned p, unsigned n)
   return x ^ (0x1 << n) - 0x1 << p;
How are you specifying x?? A binary number, a hex number??
LoraAuthor Commented:
x-binary number
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

LoraAuthor Commented:
Could you please help me with this one :
Write a program to remove trailing blanks and tabs from each line from output and to delete entirely blank line.
Help me please!
Just a note - compiler warns about << operator precedence - need to clarify solution....
LoraAuthor Commented:
Can You please help me with this problem?
How to write a program to print all input linesthat are longer than 80 character?
Plaes help me
Ask a new question Lora, this one is closed.

Captain Kirk, it's true, the compiler warns for presedence, but it is ok in this case. To clarify:

return x ^ (((0x1 << n) - 0x1) << p);

It's ok because - goes for << and << goes for ^

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.