PHP code for these calculations
//input binary, output hex
//uses PHP's dechex function
function binaryToHex($binIn){
$last = strlen($binIn)-1;
for($i=0; $i<=$last; $i++){ $x += $binIn[$last-$i] * pow(2,$i); }
return dechex($x);
}
Aahh yes, PHP is great and after using the function up above, I learned aobut the handy
base_convert( ) function which lets you convert any number between whatever bases you'd like.
This function takes three arguments as follows base_convert($numberYouWantToConvert,$baseOfThatNumber, $baseToConvertTo). For example, running base_convert($hexInPut, 16, 2) will convert the the hexadecimal $hexInPut from base 16 to binary. And conversely, base_convert($binIn, 2, 16) converts the binary $binIn to hexadecimal.