Does anyone know how bitwise OR parameters are used in calling a function?
Like:
function( value1 | value2 );
does anyone know how this works?
Does anyone know how bitwise OR parameters are used in calling a function?
Like:
function( value1 | value2 );
does anyone know how this works?
bit masking, or checking if certain bits are set
eg if i had a Mask of 1
0000001 in binary
and say i set a 'var' to 21
0010101 in binary
in both the mask an var the 1 bit is set, so do whatever when Mask is true
i would use the bitwise '&' operator to check and see if the bit's were set
if(var & Mask)
// do something
example:
Code:#define MASK_1 1 // 1(00000001) #define MASK_2 1 << 1 // 2(00000010) #define MASK_3 1 << 2 // 4(00000100) bool checkmask(int var) { if(var & MASK_1) // do something if(var & MASK_2) // do something else if(var & MASK_3) // do something }
ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.
it combines the bits. All bits set in both values are passed in.Originally posted by Unregistered
Does anyone know how bitwise OR parameters are used in calling a function?
Like:
function( value1 | value2 );
does anyone know how this works?
value1 = 00110000
value2 = 01100110
value1 | value2 = 01110110
Unregistered,
Hershlag and no-one have both posted great information, but I'm uncertain that either response goes to your question.
You ask about a function "call", but what about the "prototype/function definition"?
Uncharted territory: You've taken advantage of the bitwise operator within a function "call", (assuming no compiler error), but ...
This would seem to be something that the compilation of your code would "unearth". That is, it either "flies", or it doesn't.
Offhand, I would suggest that it won't work. The reason? Unlike the "call", the definition requires a "type", i.e. a char, an int, a float, a reference, etc.
Unless you pre-define the type of the parameter, I don't see how you can access the function.
More specifically, we're assuming an int (for argument's sake). Now, the user (go figure) re-defines the values to 'long doubles'.
Your "bitwise OR" may, and I stress may, work, but what about the call to the function?
Can it be done? Possibly.
Good idea? Probably not.
-Skipper
"When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow
uh that was interesting.... I don't think he's trying to declare a function prototype that way. I think he's talking about passing the two values or'd together into the function.
Anyway, I'm sure he's asking cause he saw it somewhere. WindowsAPI uses combined bitflags in lots of places and I use them myself. They are actually very common. You lost me somewhere.
Yeah skipper that is a good angle to tackle but it does somewhat insult the intelligence of our unregistered friend. This has NOTHING to do with your initial question but it goes along with what you are doing. This is called a bitfield:
You don't need to use a union for this sort of thing however some compilers are weird about this stuff and mis-align data.Code:typedef unsigned char byte; //this just saves you some typing union bitfield { byte Byte; struct { byte hi : 4; /*the number after the colon is how many bits this variable takes up*/ byte lo : 4; } bits; }; int main() { bitfield bf; bf.Byte = 0x88; cout << bf.bits.hi << " " << bf.bits.lo; return 0; }
Last edited by master5001; 07-23-2002 at 04:13 AM.
Master5001,
Sorry about the "pregnant pause". (A death in the family.)
My intent was certainly never to insult anyone's intelligence though I appreciate your insight. (My own is limited enough without disparaging someone else's. )Yeah skipper that is a good angle to tackle but it does somewhat insult the intelligence of our unregistered friend.
Sorry if I "lost" anyone but I don't make assumptions regarding an unregistered guest's knowledge/understanding of the subject matter.
-Skipper
"When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow