Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > LSB aligned data

Reply
Thread Tools

LSB aligned data

 
 
wongjoekmeu@yahoo.com
Guest
Posts: n/a
 
      04-18-2008
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
 
Reply With Quote
 
 
 
 
red floyd
Guest
Posts: n/a
 
      04-18-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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.
 
Reply With Quote
 
 
 
 
SeanW
Guest
Posts: n/a
 
      04-18-2008
> According to the manual the data is LSB aligned.

Note also the difference between alignment and byte order.

http://en.wikipedia.org/wiki/Endianness
http://en.wikipedia.org/wiki/Data_structure_alignment

Depending on your platform, you may need to do some
conversion of each number.

Sean

 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      04-18-2008
On 18 avr, 20:57, red floyd <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote:


> > 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 ?


> 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.

--
James Kanze (GABI Software) email:(E-Mail Removed)
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Portable way to mask the LSB Francis Moreau C Programming 7 05-31-2010 08:11 PM
LSB and Ruby daniel åkerud Ruby 0 02-28-2008 03:09 PM
Reversing Bit Order.. i.e. MSB becomes bit 0, LSB becomes bit 15 benn686@hotmail.com C++ 9 08-22-2007 12:13 AM
Ruby has not been added to LSB 3.2 (but both Perl and Python) GinTon Ruby 6 05-27-2007 08:37 PM
H1 header: left or center aligned DU HTML 8 10-08-2003 07:05 AM



Advertisments