Page 1 of 1

PHP convert ascii integer to packed decimal and zoned

Posted: Fri Feb 03, 2006 3:27 am
by amyarjun
Weirdan | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
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:

Code: Select all

<?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:

Code: Select all

<?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 u help me on this?
Weirdan | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]