bin_to_str() currently* outputs errant non-ASCII characters, eg. '�'. I am successfully stripping them via preg_replace('/[[:^print:]]/', '', join($res));, but this feels hacky to me--we shouldn't be encountering non-ASCII characters at all. Perhaps it's an off-by-one error in the for loop parameters?
*Under certain circumstances (like with input string 0123456789ABCDEF)