473,398 Members | 2,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

arrays -- can they be words, not bytes?

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
Oct 17 '07 #1
6 1528
In our last episode, <13*************@corp.supernews.com>, the lovely and
talented Bint broadcast on comp.lang.php:
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?
Your question appears to be nonsense. In PHP, arrays are a compound type.
The keys must be integers or strings (yours appear to be integers so far).
Values may be any PHP type including array. The maximum size of the types
are, in general, platform dependant, but I do not know of a platform on
which PHP will compile in which you would be limited to 8 bits. If you are
getting byte values out of an array it is because someone, possibly you, put
byte values into the array. If you want 16-bit values in an array, put
16-bit values in it.

PHP is a high-level language. Ordinarily you should not know or care what
the low-level memory arrangements are. If you are trying to do something
special, you'll have to tell us what it is.

--
Lars Eighner <http://larseighner.com/ <http://myspace.com/larseighner>
Countdown: 460 days to go.
What do you do when you're debranded?
Oct 17 '07 #2
"Bint" <bi**@csgs.comwrote in news:13*************@corp.supernews.com:
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?
Hmm, I think you're a bit confused, or at least I am.

Put whatever you want in the array:

$storeAddress['Kamloops'] = "128 Harry Street";
$storeAddress['Toronto'] = "2555 Yonge Street";

And what is a 16-bit word?
Oct 17 '07 #3
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.
js*******@attglobal.net
==================

Oct 17 '07 #4
Good Man wrote:
"Bint" <bi**@csgs.comwrote in news:13*************@corp.supernews.com:
>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?

Hmm, I think you're a bit confused, or at least I am.

Put whatever you want in the array:

$storeAddress['Kamloops'] = "128 Harry Street";
$storeAddress['Toronto'] = "2555 Yonge Street";

And what is a 16-bit word?
Assembler term - two 8-bit bytes handled as one 16 bit word. And 4
bytes can be handled as a 32 bit DWORD.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Oct 17 '07 #5
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" <js*******@attglobal.netwrote in message
news:D_******************************@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.
js*******@attglobal.net
==================

Oct 17 '07 #6
Bint wrote:
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" <js*******@attglobal.netwrote in message
news:D_******************************@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.
js*******@attglobal.net
==================


Nope, not really. But I think I'd do that processing in C anyway.
Either call it as an external module or write an extension to PHP for it.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Oct 17 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: matt melton | last post by:
Hi there, I am trying to write a method that accepts an array of any primitive type and will return the same array without copying memory as an array of bytes. ie. I'd like to be able to do...
2
by: hall | last post by:
I have a question regarding where memory is allocated when arrays are created. I'll illustrate this by example. I may be wrong on some details, do feel free to correct me. The code piece: int...
2
by: LeTubs | last post by:
Hi I have few questions in realtion to arrays, I assume that they are not available as a data type, is this correct ? The reason why is that I want to store a large amount of data for a...
9
by: Charles Banas | last post by:
i've got an interesting peice of code i'm maintaining, and i'd like to get some opinions and comments on it, hopefully so i can gain some sort of insight as to why this works. at the top of the...
197
by: Steve Kobes | last post by:
Is this legal? Must it print 4? int a = {{1, 2}, {3, 4}}, *b = a; printf("%d\n", *(b + 3)); --Steve
3
by: AC | last post by:
I noticed that if I declared an array a as int a, sizeof a is 6 * sizeof(int). This means that a occupies 6*sizeof(int) consecutive bytes, right? So I can consider, (int *) &a as a pointer to an...
39
by: Martin Jørgensen | last post by:
Hi, I'm relatively new with C-programming and even though I've read about pointers and arrays many times, it's a topic that is a little confusing to me - at least at this moment: ---- 1)...
41
by: Rene Nyffenegger | last post by:
Hello everyone. I am not fluent in JavaScript, so I might overlook the obvious. But in all other programming languages that I know and that have associative arrays, or hashes, the elements in...
152
by: vippstar | last post by:
The subject might be misleading. Regardless, is this code valid: #include <stdio.h> void f(double *p, size_t size) { while(size--) printf("%f\n", *p++); } int main(void) { double array = { {...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.