PhpDig.net

Go Back   PhpDig.net > General Forums > Coding & Tutorials

Reply
 
Thread Tools
Old 02-05-2006, 07:28 PM   #1
amyarjun
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?
amyarjun is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 04:42 PM.


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