PhpDig.net

PhpDig.net (http://www.phpdig.net/forum/index.php)
-   Coding & Tutorials (http://www.phpdig.net/forum/forumdisplay.php?f=31)
-   -   PHP convert ascii integer to packed decimal and zoned (http://www.phpdig.net/forum/showthread.php?t=2359)

amyarjun 02-05-2006 06:28 PM

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?


All times are GMT -8. The time now is 07:15 AM.

Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright © 2001 - 2005, ThinkDing LLC. All Rights Reserved.