You are here: Re: arrays -- can they be words, not bytes? « PHP Programming Language « IT news, forums, messages
Re: arrays -- can they be words, not bytes?

Posted by Bint on 10/17/07 20:25

Yeah, I guess I'm trying to do something low-level with this high-level
lanugage. I'm new to PHP so I'm trying to figure out how these fancy
keyword-based arrays work with old-school byte arrays.

I'm sending images wirelessly to a php script. The image, originally a grid
of pixels, each 16-bits deep, is run-length-encoded into a smaller C array
of unsigned shorts (16 bit words). That C array is base64 encoded into an
ASCII string so that I can send it via HTTP POST command to a PHP script.

The PHP script sees my base64 encoded array as a variable, which I can
easily base64 decode into a php "array". But it is proving trickier to
access my pixel values, because now the array is not a C array, but a PHP
one. If I look at the value of array[0], then I don't get the number that
was in array[0] before I sent it.

I can work around it, by accessing each byte of the PHP array:

$myoriginalarray[0] = ord($phparray[0]) + ord($phparray[1]) << 8;

But that is complicated and I just thought there might be some simpler way
of telling PHP "hey, I have an array of unsigned shorts here".
Maybe not.

B






"Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
news:D_SdneeS0bxw8YvanZ2dnUVZ_qHinZ2d@comcast.com...
> Bint wrote:
>> I have an array whose elements I'm accessing, like array[0], array[1],
>> etc.
>> However, the data is meant to be 16-bit words, not bytes. I'm getting
>> byte values right now. Is there
>> any way I can tell php that an array is composed of words and not bytes?
>>
>> Thanks
>> B
>>
>>
>>
>
> Not really. PHP is not meant for low-level bit manipulation. And you
> can't really control the size of the word - it can differ between 32 and
> 64 bit architectures, for instance.
>
> What are you string in those words, anyway?
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstucklex@attglobal.net
> ==================
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация