79231055

Date: 2024-11-27 16:20:52
Score: 1
Natty:
Report link

Why checking huge listings? With photo files, normally only occurrence is of interest, not the former (possibly inactive) switch position of the camera! The effective flash event can therefore be queried with just a few binary comparisons (see code snippet below). Have fun!

    function effectiveFlash($flagval) {
/*
    This function uses just 4 major bit comparisons
    and responds with an easy-to-understand answer.
    However, the code could be even shorter, e.g.
    by returning simple symbols instead of text.
*/
    $result = 'not fired'; // First we assume nothing!
    // 1st check: Bit-1
    if(($flagval & 1) > 0) {
        $result = 'fired';
        // Prepare opening and closing text part for possible subsequent information:
        $sep = ' (Setting: ';
        $end = "";
        // 2nd check: Bit-16 plus possibly enclosed Bit-8
        if (($flagval & 24) > 0) {
            if (($flagval & 24) == 24) $result .= $sep . 'Auto';
            else $result .= $sep . 'Compulsory';
            $sep = ' + ';
            $end = ')';
        }
        // 3rd check: Bit-64
        if(($flagval & 64) > 0) {
            $result .= $sep . 'Red Eye Reduction';
            $sep = ' + ';
            $end = ')';
        }
        // 4th check: Bit-4 plus possibly enclosed Bit-2
        if(($flagval & 6) > 0) {
            if(($flagval & 6) == 6) $result .= $sep . 'Return Light';
            else $result .= $sep . 'No Return Light';
            $sep = ' + ';
            $end = ')';
        }
        // Now add the closing bracket ... that's it!
        $result .= $end;
    }
    return 'Flash ' . $result;
}

// Examples:
echo effectiveFlash(1)."<br>\n";
echo effectiveFlash(16)."<br>\n";
echo effectiveFlash(31)."<br>\n";
echo effectiveFlash(77)."<br>\n";

The Output would be like this:
  "Flash fired"
  "Flash not fired"
  "Flash fired (Setting: Auto + Return Light)"
  "Flash fired (Setting: Compulsory + Red Eye Reduction + No Return Light)"
Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Unregistered user (0.5):
  • Starts with a question (0.5): Why
  • Low reputation (1):
Posted by: ejomi