12-15-2008 07:41 PM
Hi,
I am new to programming.
I have a sensor that sends a data stream through a serial port. I have collect all that data in a 1D unsigned byte array. Now, lets say my 1-D array is [12][45][65][12]...... where each "[ ]" is a element of the array. Now to make sense of this data what i need to do is merge two elements the array and multipy it by 2/(2^15). i.e. My converted data should by [1245]*2/(2^15). Basically 2 bytes together makes sense. I can do a simple add of each element. Also the other problem is,data from the sensor is a stored as the 1-D array of unsigned byte. However, the converted data is supposed to be signed 16-bit integer.
Please give any suggestions on how to go about doing this.
Siddhant Shah
12-15-2008 07:59 PM
I think there is a function that does specifically what you need. You can find it under programming -> numeric -> data manipulation -> join numbers or just search "join numbers". To get two elements you could use a for loop that is half the length of the array and take the current element and join it with the next.
12-15-2008 08:11 PM
12-15-2008 08:20 PM - edited 12-15-2008 08:20 PM
Assuming you want big-endian byte order, all you need is typecast your U8 array to an U16 array as follows:

12-15-2008 08:28 PM - edited 12-15-2008 08:28 PM
Another option is "decimate&Join". (Here it is easy to change the byte order if needed).

12-28-2008 03:50 PM
Thank you very much guys.
All this information is very helpful