LSB aligned data

W

wongjoekmeu

Hello all,
I have a control software that retrieve data from an ethernet card.
The function that is used to retrieve the data takes a reference to an
unsigned char array whcih it fills for me. The data that I retrieve
are actually 16-bits. So I want to convert them to unsigned short
integers. For instance when I am expecting to retrieve ten 16 bits
data, the function wants me to allocate an unsigned char array of 20
elements to give to the retrieve function. I presume that for instance
array element 0 and 1 represents my first 16 bits value. According to
the manual the data is LSB aligned. I was wondering how I should
calculate the ten array elements of my unsigned short integer array.
Can anyone please help me out ?
RR
 
R

red floyd

Hello all,
I have a control software that retrieve data from an ethernet card.
The function that is used to retrieve the data takes a reference to an
unsigned char array whcih it fills for me. The data that I retrieve
are actually 16-bits. So I want to convert them to unsigned short
integers. For instance when I am expecting to retrieve ten 16 bits
data, the function wants me to allocate an unsigned char array of 20
elements to give to the retrieve function. I presume that for instance
array element 0 and 1 represents my first 16 bits value. According to
the manual the data is LSB aligned. I was wondering how I should
calculate the ten array elements of my unsigned short integer array.
Can anyone please help me out ?
RR

Instead of passing an array of 20 unsigned chars, pass an array of 10
unsigned shorts and cast it to an unsigned char* when you call the function.

This is common practice.
 
J

James Kanze

(e-mail address removed) wrote:
Instead of passing an array of 20 unsigned chars, pass an
array of 10 unsigned shorts and cast it to an unsigned char*
when you call the function.
This is common practice.

Maybe. Programs crashing is common practice, too. This
solution doesn't work.

The simplest solution would be to extract the values explicitly,
one by one, using shifting and or'ing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top