PHP function unpack
am 11.10.2009 16:42:01 von Gabriel Hahmann
Hi,
I'm new to the list and I've search internet and didn't find an answer
to my problem.
I'm converting a perl script to PHP and I've done almost everything.
The only part of the code that I didn't get working on PHP was:
(PERL CODE)
foreach ($b_length,$b_mac,$b_crlf,$b_crlf,$a_body) {
$d_checksum += unpack("%16n*", $_);
}
The idea is to make a 16-bit checksum of all elements
($b_length,$b_mac,$b_crlf,$b_crlf,$a_body).
I'm tried translating the code to:
$arr_checksum = array($b_length,$b_mac,$b_crlf,$b_crlf,$File_Content);
$d_checksum = 0;
foreach($arr_checksum as $check_elem){
$d_check = unpack("n*", $check_elem);
for ($i=0;$i<4;$i++){
$d_checksum += $d_check["$i"];
}
}
But the result is different. I know that unpack in perl and php are
different, but I cant find a way to translate the format %16n* of perl
to php and generate a 16-bit checksum.
Any help will be appreciated.
[]'s
Gabriel.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: PHP function unpack
am 15.10.2009 17:59:01 von Gabriel Hahmann
Hi,
I've sent this mail a few days ago, but as this list have a very high
traffic maybe my mail disappear from you inbox.
Any help would be appreciated.
Thanks in advance,
Gabriel.
On Sun, Oct 11, 2009 at 4:42 PM, Gabriel Hahmann
wrote:
> Hi,
>
> I'm new to the list and I've search internet and didn't find an answer
> to my problem.
>
> I'm converting a perl script to PHP and I've done almost everything.
> The only part of the code that I didn't get working on PHP was:
>
> (PERL CODE)
> foreach ($b_length,$b_mac,$b_crlf,$b_crlf,$a_body) {
> =A0 =A0 =A0 =A0$d_checksum +=3D unpack("%16n*", $_);
> }
>
> The idea is to make a 16-bit checksum of all elements
> ($b_length,$b_mac,$b_crlf,$b_crlf,$a_body).
>
> I'm tried translating the code to:
>
> $arr_checksum =3D array($b_length,$b_mac,$b_crlf,$b_crlf,$File_Content);
>
> $d_checksum =3D 0;
> foreach($arr_checksum as $check_elem){
> =A0 =A0 =A0 =A0$d_check =3D unpack("n*", $check_elem);
> =A0 =A0 =A0 =A0for ($i=3D0;$i<4;$i++){
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0$d_checksum +=3D $d_check["$i"];
> =A0 =A0 =A0 =A0}
> }
>
> But the result is different. I know that unpack in perl and php are
> different, but I cant find a way to translate the format %16n* of perl
> to php and generate a 16-bit checksum.
>
> Any help will be appreciated.
>
> []'s
> Gabriel.
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php