Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi, I am not clear about this question in C++? Can you please help me with this.
...



1. how do I get the inverse? is there way in bitwise operator?
2. when say mask, does it mean OR or AND mask?

Thanks agian.

What I have tried:

return b |= inverse(a); // is this correc?
Posted
Updated 7-Nov-22 6:47am
Comments
11917640 Member 7-Nov-22 6:44am    
return (b & (~a));

The tilde symbol is one way : ~. It is the binary negation operator. The boolean negation operator is the exclamation mark : !. The docs : cplusplus.com : operators[^].

What you tried, the |=, is the or equals operation.

ETA: You can display an integer in hexadecimal format like this :
C
printf( "integer value is %08X\n", integerValue );
That format specifier, the %08X part, would display eight hex digits with leading zeros.
 
Share this answer
 
v2
Comments
CPallini 7-Nov-22 12:35pm    
5.
Rick York 7-Nov-22 12:47pm    
Thank you sir.
Quote:
1. how do I get the inverse? is there way in bitwise operator?
Yes, there is, as Rick already suggested, it is the bitwise NOT (~, see Arithmetic operators - cppreference.com[^]).
Quote:
2. when say mask, does it mean OR or AND mask?
Usually is it an AND mask.

To summarize (as 11917640 Member suggested)
C++
(b & (~a))
should do the trick.
 
Share this answer
 
unsigned char operator(unsigned char a, unsigned char b)
{

    return (b |= reverse(a);
}
 
Share this answer
 
Comments
merano99 8-Nov-22 12:39pm    
You propose yourself a solution? If yes, you should explain it, if no it belongs rather above under "What I have tried".

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900