PHP School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a PHP Expert!

Join 307,175 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,545 people online right now. Registration is fast and FREE... Join Now!




Binary Conversion

 

Binary Conversion

pudge1

19 Aug, 2009 - 06:03 AM
Post #1

New D.I.C Head
*

Joined: 18 Aug, 2009
Posts: 6

So I recently made a PHP script out of a C++ Program. I have everything ready but there was one thing I couldn't convert.
CODE

<?php
$filesize = $_FILES['binary']['size'];
$bin = file_get_contents($_FILES['binary']['tmp_name'];
$input = explode('',$bin);
$output = array();

function decompressLZSS($filesize, $input, $output)
{
$inputvalue = 0;
$outputvalue = 0;
   while ($outputvalue < $filesize)
   {
   $chdr = $input[$inputvalue];
   $inputvalue++;
   for ($bit = 0; $bit < 8; $bit++)
   {
   $bitVal = ($chdr /2 (7 - $bit)) & 1;
   if ($bitVal == 0)
   {
   $output[$outputvalue] = $input[$inputvalue];
   $inputvalue++;
   $outputvalue++;
   }
   else
   {
   $temp = $input[$inputvalue] | ($input[$inputvalue + 1] *2(8));
   $distance = $temp & 0x7ff;
   $leng = ($temp /2 (11)) + 3;
   $inputvalue += 2;
   if ($distance > $outputvalue || $distance == 0)
                   return 0;
   for ($temp = 0; $temp < $leng; $temp++)
   {
   $output[$outputvalue] = $output[$outputvalue - $distance];
   $outputvalue++;
   if ($outputvalue == $filesize)
   break;
   }
   }
   if ($outputvalue == $filesize)
               break;
   }
   }
   return $inputvalue;
}
?>


It's the last variable to be used in the function. You are supposed to set it as like an array of where the output is to go. So I just made an array for the variable, will this work?

This post has been edited by pudge1: 19 Aug, 2009 - 06:04 AM

User is offlineProfile CardPM
+Quote Post

 
Reply to this topicStart new topic
Replies(1 - 1)

Valek

RE: Binary Conversion

20 Aug, 2009 - 12:24 AM
Post #2

The Real SkyNet
Group Icon

Joined: 8 Nov, 2008
Posts: 627



Thanked: 43 times
Dream Kudos: 175
My Contributions
If you're actually putting output into it, you'll want to change your function declaration. Try this instead:

CODE
function decompressLZSS($filesize, $input, &$output)


The ampersand before $output up there specifies that it's an argument passed by reference, so if you modify $output in the function, it will modify whatever variable you've sent with that function in the place of $output. Otherwise, you'd only be modifying it in the local scope of the function and you'd lose your data once the function completed, as it's only returning $inputvalue.

This post has been edited by Valek: 20 Aug, 2009 - 12:24 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 07:21PM

Live PHP Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month