473,569 Members | 2,991 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1541
In our last episode, <13************ *@corp.supernew s.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.comw rote in news:13******** *****@corp.supe rnews.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*******@attgl obal.net
=============== ===

Oct 17 '07 #4
Good Man wrote:
"Bint" <bi**@csgs.comw rote in news:13******** *****@corp.supe rnews.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*******@attgl obal.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:

$myoriginalarra y[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*******@attg lobal.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*******@attgl obal.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:

$myoriginalarra y[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*******@attg lobal.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*******@attgl obal.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*******@attgl obal.net
=============== ===

Oct 17 '07 #7

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

Similar topics

5
13904
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 something like: char chars = "Hello!"; byte bytes = (byte) chars;
2
5332
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 p; Creates a 2dimensional array. p can be thought of as a pointer, containing the adres of the first element in the array. The memory is
2
1785
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 paticular record and a bit concered about the size of record. (I assuming that an array of 1000 ints will be smaller than 1000 records of table dailyclose...
9
6656
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 function (which was translated from Fortran code), among other heinous and numerous declarations, is this bit: static float bbuff; static int...
197
5630
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
1391
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 array of 2*3*1=6 ints. Is this correct? This code works fine for me : #include <stdio.h>
39
19581
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) What's the difference between these 3 statements: (i) memcpy(&b, &KoefD, n); // this works somewhere in my code
41
4901
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 the hash are alphabetically sorted if the key happens to be alpha numeric. Which I believe makes sense because it allows for fast lookup of a key.
152
9768
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 = { { 3.14 }, { 42.6 } }; f((double *)array, sizeof array / sizeof **array); return 0;
0
7618
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7926
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
6287
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5223
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3657
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2117
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
946
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.