Last active
January 29, 2016 09:45
-
-
Save superhero/12ffdcf0c98966a8a4b1 to your computer and use it in GitHub Desktop.
Do an action by bit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function actionByBit($actions, $dec, $bits) | |
{ | |
for($i = 0, $count = count($actions); $bits > 0; $i++) | |
if($dec & 1 << --$bits && $i < $count) | |
$actions[$i](); | |
} | |
$hex = '70 0C 00 00'; | |
$dec = hexdec($hex); | |
$bits = 32; | |
$actions = | |
[ | |
function(){ echo 'NOALARM'.PHP_EOL; }, | |
function(){ echo 'INACTIVE'.PHP_EOL; }, | |
function(){ echo 'LOSS_OF_SIGNAL'.PHP_EOL; }, | |
function(){ echo 'LOSS_OF_FRAME'.PHP_EOL; }, | |
function(){ echo 'DRIFT_OF_WINDOW'.PHP_EOL; }, | |
function(){ echo 'SIGNAL_FAIL'.PHP_EOL; }, | |
function(){ echo 'SIGNAL_DEGRADE'.PHP_EOL; }, | |
function(){ echo 'LOSS_OF_GEM_CHAN_DELIN'.PHP_EOL; }, | |
function(){ echo 'REMOTE_DEFECT'.PHP_EOL; }, | |
function(){ echo 'TRANSMITTER_FAILURE'.PHP_EOL; }, | |
function(){ echo 'START_UP_FAILURE'.PHP_EOL; }, | |
function(){ echo 'LOSS_OF_ACK'.PHP_EOL; }, | |
function(){ echo 'DYING_GASP'.PHP_EOL; }, | |
function(){ echo 'LOSS_OF_PLOAM_SYNC'.PHP_EOL; }, | |
function(){ echo 'MESSAGE_ERROR'.PHP_EOL; }, | |
function(){ echo 'PHYS_EQUIP_ERROR'.PHP_EOL; }, | |
function(){ echo 'BIT_16_NOT_USED'.PHP_EOL; }, | |
function(){ echo 'BIT_17_NOT_USED'.PHP_EOL; }, | |
function(){ echo 'EXCESSIVE_BIP_ERRORS_ONU_DISABLED'.PHP_EOL; }, | |
function(){ echo 'EXCESSIVE_BIP_ERRORS_ONU_NOT_DISABLED'.PHP_EOL; }, | |
function(){ echo 'US_RX_POWER_ERROR_ONU_DISABLED'.PHP_EOL; }, | |
function(){ echo 'US_RX_POWER_ERROR_ONU_NOT_DISABLED'.PHP_EOL; }, | |
function(){ echo 'ROGUE_ONU'.PHP_EOL; } | |
]; | |
actionByBit($actions, $dec, $bits); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment