# Thread: bitwise OR in function parameters

1. ## bitwise OR in function parameters

Does anyone know how bitwise OR parameters are used in calling a function?

Like:
function( value1 | value2 );

does anyone know how this works?

2. 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

// do something

example:

Code:
```#define MASK_1  1 // 1(00000001)
#define MASK_2  1 << 1  // 2(00000010)
#define MASK_3  1 << 2  // 4(00000100)

{
//        do something

//        do something else

//        do something

}```

3. ## Re: bitwise OR in function parameters

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?
it combines the bits. All bits set in both values are passed in.

value1 = 00110000
value2 = 01100110

value1 | value2 = 01110110

4. 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

5. 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.

6. 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:

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;
}```
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.

7. Master5001,

Sorry about the "pregnant pause". (A death in the family.)

Yeah skipper that is a good angle to tackle but it does somewhat insult the intelligence of our unregistered friend.
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. )

Sorry if I "lost" anyone but I don't make assumptions regarding an unregistered guest's knowledge/understanding of the subject matter.

-Skipper

Popular pages Recent additions