$dec /= 16;
} while ($dec >= 1);
+ /*
+ * We need hexadecimal strings with leading zeros if the length cannot
+ * be divided by 2
+ */
+ if ((strlen($hex) % 2) != 0) {
+ // Prepend a zero
+ $hex = '0' . $hex;
+ } // END - if
+
// Return the hexadecimal string
return $sign . $hex;
}
* @param $dec Decimal number
* @return $asc An ASCII string
*/
- public final function dec2asc ($deg) {
+ public final function dec2asc ($dec) {
// First convert the number into a hexadecimal string
- $hex = $this->dec2hex($deg);
+ $hex = $this->dec2hex($dec);
// Then convert it into the ASCII string
$asc = $this->hex2asc($hex);
for ($idx = 0; $idx < strlen($hex); $idx+=2) {
// Get the decimal number of the chunk
$part = hexdec(substr($hex, $idx, 2));
- $this->debugOutput(__FUNCTION__ . ': part(' . strlen($part) . ')=' . $part);
// Add it to the final string
$asc .= chr($part);