Oihana PHP

countFlags.php

Table of Contents

Functions

countFlags()  : int
Counts the number of active flags (bits set to 1) in a bitmask.

Functions

countFlags()

Counts the number of active flags (bits set to 1) in a bitmask.

countFlags(int $mask) : int

This function is useful when you want to know how many flags are currently active.

Parameters
$mask : int

The bitmask to analyze.

Tags
example
use function oihana\core\bits\countFlags;

const FLAG_A = 1 << 0 ; // 1
const FLAG_B = 1 << 1 ; // 2
const FLAG_C = 1 << 2 ; // 4

$mask = FLAG_A | FLAG_B;  // 3
echo countFlags($mask);   // Outputs: 2

$mask = FLAG_A | FLAG_B | FLAG_C ; // 7
echo countFlags( $mask ) ; // Outputs: 3

$mask = 0; // no flags
echo countFlags($mask); // Outputs: 0
author

Marc Alcaraz (ekameleon)

since
1.0.7
Return values
int

The number of bits set to 1 in the mask.


        
On this page

Search results