| 1 | | 2 | | 3 | | 4 | | 5 | | 6 | | 7 | | 8 | | 9 | | 10 | | 11 | | 12 | | 13 | | 14 | | 15 | | 16 | | 17 | | 18 | | 19 | | 20 | | 21 | | 22 | | 23 | | 24 | | 25 | | 26 | | 27 | | 28 | | 29 | | 30 | | 31 | | 32 | | 33 | | 34 | | 35 | | 36 | | 37 | | 38 | | | ############################## | | function BCD($Characters,$HR=false){ | | ############################## | | # Base16 to Base2 Converter. | | # Useage: bcd('FF',false); | | # Converts base16(Hexadecimal) | | # to base2(Binary) with the option | | # to return it in a human readable | | # format. | | ############################## | | $BCD = array ( | | 0 => '0000', | | 1 => '0001', | | 2 => '0010', | | 3 => '0011', | | 4 => '0100', | | 5 => '0101', | | 6 => '0110', | | 7 => '0111', | | 8 => '1000', | | 9 => '1001', | | 'A' => '1010', | | 'B' => '1011', | | 'C' => '1100', | | 'D' => '1101', | | 'E' => '1110', | | 'F' => '1111', | | ); | | $Hex = 'ABCDEF'; | | $BinDec = array(); | | $Characters= str_split($Characters); | | foreach ( $Characters as $Character ) { | | if ( is_numeric($Character) || stristr($Hex, $Character) ) $BinDec[] = $BCD[$Character]; | | } | | if ( $HR ) $BinDec = implode('-',$BinDec); | | else $BinDec = implode('',$BinDec); | | return($BinDec); | | } |
|