Solved

# problems with function

Posted on 2000-03-02
217 Views
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
Question by:Lora
• 3
• 2
• 2

LVL 4

Expert Comment

ID: 2577031
How are you specifying x?? A binary number, a hex number??
0

Author Comment

ID: 2577059
x-binary number
0

LVL 3

Accepted Solution

LucHoltkamp earned 5 total points
ID: 2577108
unsigned inverse(unsigned x, unsigned p, unsigned n)
{
return x ^ (0x1 << n) - 0x1 << p;
}
0

Author Comment

ID: 2577323
Write a program to remove trailing blanks and tabs from each line from output and to delete entirely blank line.
0

LVL 4

Expert Comment

ID: 2577334
Just a note - compiler warns about << operator precedence - need to clarify solution....
0

Author Comment

ID: 2577413
How to write a program to print all input linesthat are longer than 80 character?
Plaes help me
0

LVL 3

Expert Comment

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

Question has a verified solution.

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

### Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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.