I need to check which hexadecimal flags are included in a certain decimal variable. At the moment the script just works for small decimals but I've some longer ones.
In the following example it shows me the right flags when I check the flags inside $decimal2
, but it doesn't work with $decimal
.
I don't know the reason for this behaviour and what has to be changed.
This is the example demo.
$decimal = 613090029426844e18; // doesn't work
$decimal2 = 64; //works
const FLAG_1 = 0x1;
const FLAG_2 = 0x2;
const FLAG_3 = 0x4;
const FLAG_4 = 0x4;
const FLAG_5 = 0x32;
const FLAG_6 = 0x40;
const FLAG_7 = 0x400;
function show_flags ($decimal) {
if ($decimal & FLAG_1) {
echo "Flag 1 included.<br>\n";
}
if ($decimal & FLAG_2) {
echo "Flag 2 included.<br>\n";
}
if ($decimal & FLAG_3) {
echo "Flag 3 included.<br>\n";
}
if ($decimal & FLAG_4) {
echo "Flag 3 included.<br>\n";
}
if ($decimal & FLAG_5) {
echo "Flag 3 included.<br>\n";
}
if ($decimal & FLAG_6) {
echo "Flag 3 included.<br>\n";
}
if ($decimal & FLAG_7) {
echo "Flag 3 included.<br>\n";
}
}
show_flags($decimal);