Jump to content

What does the | mean when in an argument.


sircatsquid

Recommended Posts

I tried it and it looks like it does math. But I thought it was going to try both arguments can't find the doc for it not really sure what to search for. :/

is_int($arg1|$arg2):

This results in the sum of arg 1 and 2 is thrown to is_int

Link to comment
Share on other sites

The | is an operator tha does a logical OR operation with each of the bits of the two arguments. I don't see why somebody would need to do that in the is_int() function because both should be integers to begin with if you want to do bit operations. You only do this with function arguments when the arguments are flags (their binary representation is all zeroes except for one bit). Using the | operator can add several flags together so that the function gets the information of multiple flags with just one argument.

Link to comment
Share on other sites

The | is an operator tha does a logical OR operation with each of the bits of the two arguments. I don't see why somebody would need to do that in the is_int() function because both should be integers to begin with if you want to do bit operations. You only do this with function arguments when the arguments are flags (their binary representation is all zeroes except for one bit). Using the | operator can add several flags together so that the function gets the information of multiple flags with just one argument.
Okay, then I know. :) I just used is_int cause it was shorter to write, But I was thinking if I could send multiple arguments to one function argument.
Link to comment
Share on other sites

You'll end up with the values ORd together in a bitwise fashion. Assume you have the numbers ten and 2, which are expressed in binary: 2 = 10ten = 1010 doing 2 | 10 will be a bitwise OR, and you will end up with : 00101010____1010 So the value will still be ten. The result of a bitwise OR means that any bit that is 1 in either operand will be set to 1 in the result. A bitwise AND (&) means that both bits in the operands need to be set to 1 in order for the result bit to be 1. A bitwise XOR means that only one or the other, but not both, bits need to be set to 1. This is bitwise arithmetic, you can research that for more information.

Link to comment
Share on other sites

You'll end up with the values ORd together in a bitwise fashion. Assume you have the numbers ten and 2, which are expressed in binary: 2 = 10ten = 1010 doing 2 | 10 will be a bitwise OR, and you will end up with : 00101010____1010 So the value will still be ten. The result of a bitwise OR means that any bit that is 1 in either operand will be set to 1 in the result. A bitwise AND (&) means that both bits in the operands need to be set to 1 in order for the result bit to be 1. A bitwise XOR means that only one or the other, but not both, bits need to be set to 1. This is bitwise arithmetic, you can research that for more information.
Okay, thanks I will look into that :)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...