[SR-Users] How to check a bit (1/0) of a pseudo-variable?
Daniel-Constantine Mierla
miconda at gmail.com
Thu Jun 16 16:15:06 CEST 2011
On Jun 16, 2011, at 2:03 PM, Iñaki Baz Castillo <ibc at aliax.net> wrote:
> 2011/6/16 Daniel-Constantin Mierla <miconda at gmail.com>:
>> that function is probably for ser-like AVPs.
>>
>> back to your original need, you can use directly if conditions like:
>>
>> if($var(x) & 2) { ... }
>>
>> will be true if the second bit is set. You have to use the power of two for
>> the appropriate integer value to match the bit position.The master branch has bitwise left/right shift operations as well
>
> Ok, so the above example if($var(x) & 2) { ... } will just work
> because the number 2 has the bit 2 with value 1 (well, in fact the bit
> 1 as the first one is the bit 0). But if I want to compare the bit 5 I
> need first to get 2^5 (for the second & operator) which I can get
> using bitwise left/right shift functions, am I right? (since there is
> no way in kamailio to calculate 2^N directly).
You can do 2*2*2... to get the power of two. Doing it in a while loop gives dynamic power parameter. Other option is to use Lua for example.
... until the left shift gets in 3.1 - if you can test the patch from master and all goes fine, then it may happen faster :-)
Cheers,
Daniel
>
More information about the sr-users
mailing list