• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 226
  • Last Modified:

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
0
Lora
Asked:
Lora
  • 3
  • 2
  • 2
1 Solution
 
captainkirkCommented:
How are you specifying x?? A binary number, a hex number??
0
 
LoraAuthor Commented:
x-binary number
0
 
LucHoltkampCommented:
unsigned inverse(unsigned x, unsigned p, unsigned n)
{
   return x ^ (0x1 << n) - 0x1 << p;
}
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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!
0
 
captainkirkCommented:
Just a note - compiler warns about << operator precedence - need to clarify solution....
0
 
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
0
 
LucHoltkampCommented:
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 ^

Luc
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now