LSB aligned data

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • wongjoekmeu@yahoo.com

    LSB aligned data

    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
  • red floyd

    #2
    Re: LSB aligned data

    wongjoekmeu@yah oo.com 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.

    Comment

    • James Kanze

      #3
      Re: LSB aligned data

      On 18 avr, 20:57, red floyd <no.s...@here.d udewrote:
      wongjoek...@yah oo.com 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:james.kan ze@gmail.com
      Conseils en informatique orientée objet/
      Beratung in objektorientier ter Datenverarbeitu ng
      9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

      Comment

      Working...