Solved

problems with function

Posted on 2000-03-02
7
214 Views
Last Modified: 2010-04-02
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
Comment
Question by:Lora
  • 3
  • 2
  • 2
7 Comments
 
LVL 4

Expert Comment

by:captainkirk
Comment Utility
How are you specifying x?? A binary number, a hex number??
0
 

Author Comment

by:Lora
Comment Utility
x-binary number
0
 
LVL 3

Accepted Solution

by:
LucHoltkamp earned 5 total points
Comment Utility
unsigned inverse(unsigned x, unsigned p, unsigned n)
{
   return x ^ (0x1 << n) - 0x1 << p;
}
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:Lora
Comment Utility
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
 
LVL 4

Expert Comment

by:captainkirk
Comment Utility
Just a note - compiler warns about << operator precedence - need to clarify solution....
0
 

Author Comment

by:Lora
Comment Utility
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
 
LVL 3

Expert Comment

by:LucHoltkamp
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now