Solved

problems with function

Posted on 2000-03-02
7
215 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
ID: 2577031
How are you specifying x?? A binary number, a hex number??
0
 

Author Comment

by:Lora
ID: 2577059
x-binary number
0
 
LVL 3

Accepted Solution

by:
LucHoltkamp earned 5 total points
ID: 2577108
unsigned inverse(unsigned x, unsigned p, unsigned n)
{
   return x ^ (0x1 << n) - 0x1 << p;
}
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:Lora
ID: 2577323
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
ID: 2577334
Just a note - compiler warns about << operator precedence - need to clarify solution....
0
 

Author Comment

by:Lora
ID: 2577413
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
ID: 2579205
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

863 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

25 Experts available now in Live!

Get 1:1 Help Now