|
02-05-2006, 06:28 PM | #1 |
Green Mole
Join Date: Feb 2006
Posts: 1
|
PHP convert ascii integer to packed decimal and zoned
Hi there im making connection between linux and as400
i have done conversion from ascii to ebcdic i have also done conversion to packed decimal and zoned decimal but the as400 replying decimal error im still trying to figure out why below is my code: for packed: <?php function int2pack($value, $length = 0) { //$value = $this->asc2hex($value); if ($length == 0) $length = strlen($value); if ($length % 2) { $length = $length; } else { $length = $length + 1; } $value = str_pad($value, $length, '0', STR_PAD_LEFT); return pack('H'.$length, $value); } ?> for zoned: <?php function int2zone($value, $length = 0) { if ($length == 0) $length = strlen($value); $value = str_pad($value, $length, '0', STR_PAD_LEFT); for($i=0; $i<$length; $i++) { $num = substr($value, $i, 1); //echo $i.'. '. $num."<br>\n"; $znum = 0xF0 + intval($num); $tznum .= pack('C', $znum); } return $tznum; } ?> can anyone help on this? |