Created
July 18, 2011 22:27
-
-
Save johnciacia/1090856 to your computer and use it in GitHub Desktop.
This file contains 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 | |
/** | |
* Calculate the binary value needed to | |
* display hexidecmal 0-F on a seven-segment | |
* display for an ARM | |
*/ | |
(strpos($argv[1], "a") !== false) ? $a = 1 : $a = 0; | |
(strpos($argv[1], "b") !== false) ? $b = 1 : $b = 0; | |
(strpos($argv[1], "c") !== false) ? $c = 1 : $c = 0; | |
(strpos($argv[1], "d") !== false) ? $d = 1 : $d = 0; | |
(strpos($argv[1], "e") !== false) ? $e = 1 : $e = 0; | |
(strpos($argv[1], "f") !== false) ? $f = 1 : $f = 0; | |
(strpos($argv[1], "g") !== false) ? $g = 1 : $g = 0; | |
$s = "{$f}{$g}{$e}{$d}{$c}{$b}{$a}0000000000"; | |
$v = base_convert($s, 2, 16); | |
$v = str_pad($v, 8,"0", STR_PAD_LEFT); | |
echo "0x{$v}\n"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment