note 118164 added to language.operators.bitwise
| From: | luis at rosety dot com | Date: | Sun, 18 Oct 2015 14:05:51 +0000 |
| Subject: | note 118164 added to language.operators.bitwise | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-203977@lists.php.net to get a copy of this message | ||
Example of function using bitwise operations for converting hexadecimal color (usually given as 6
hexadecimal digit string, into separated RGB integers)
<?php
function hex2rgb($hex){
$dec = hexdec($hexcolor); // $hex string to decimal value
$r = $dec & hexdec('FF0000'); //Mask for red
$g = $dec & hexdec('00FF00'); //Mask for green
$b = $dec & hexdec('0000FF'); //Mask for blue
return array($r>>16, $g>>8, $b); // Shift full right each color from its
original position
}
?>
Example of use
<?php
$rgb = hex2rgb('112233');
echo "red: ".$rgb[0]."\n";
echo "green: ".$rgb[1]."\n";
echo "blue: ".$rgb[2]."\n";
?>
Would produce:
red: 17
green: 34
blue: 51
Since:
dechex(17) = '#11'
dechex(34) = '#22'
dechex(51) = '#33'
----
Server IP: 72.52.91.14
Probable Submitter: 2001:7e8:c600:5501:4578:33be:1acb:8b4b
----
Manual Page -- http://php.net/manual/en/language.operators.bitwise.php
Edit -- https://master.php.net/note/edit/118164
Del: integrated -- https://master.php.net/note/delete/118164/integrated
Del: useless -- https://master.php.net/note/delete/118164/useless
Del: bad code -- https://master.php.net/note/delete/118164/bad+code
Del: spam -- https://master.php.net/note/delete/118164/spam
Del: non-english -- https://master.php.net/note/delete/118164/non-english
Del: in docs -- https://master.php.net/note/delete/118164/in+docs
Del: other reasons-- https://master.php.net/note/delete/118164
Reject -- https://master.php.net/note/reject/118164
Search -- https://master.php.net/manage/user-notes.php