473,465 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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
Jun 27 '08 #1
2 2408
wo*********@yahoo.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.
Jun 27 '08 #2
On 18 avr, 20:57, red floyd <no.s...@here.dudewrote:
wongjoek...@yahoo.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:ja*********@gmail.com
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

Jun 27 '08 #3

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

Similar topics

22
by: Marek Mand | last post by:
How to create a functional *flexible* UL-menu list <div> <ul> <li><a href=""></li> <li><a href=""></li> <li><a href=""></li> </ul> </div> (working in IE, Mozilla1.6, Opera7 (or maybe even...
7
by: serikas | last post by:
Is there a way to get aligned dynamically allocated memory? (provided that the requested memory size is a power of 2.) For example, if I request 128 bytes of memory, can I implement an allocator...
2
by: esther s via SQLMonster.com | last post by:
there are one table with a column with 16 varchar, eg. ________1245678( _ stands for space.).the database size is 15 MB. when using bcp, right-aligned data will be display. Can i change it...
1
by: Vinay Jain | last post by:
If we have aligned output enabled in psql...the output is aligned on basis of the maximum length of data being displyed...is it true?? how this thing is coded and where (in which file) I am using...
9
by: Spoon | last post by:
Hello everyone, As far as I understand, if I request a uint8_t buffer, it could be allocated anywhere. uint8_t *buf = new uint8_t By anywhere, I mean e.g. it could start at an odd address....
29
by: K. Jennings | last post by:
I would like to get the result of malloc() such that it is aligned on a given boundary - 8, in this case. Assuming that sizeof(u64) is 8, will u64 *p = malloc(N) ; do the trick in general? ...
15
by: shaanxxx | last post by:
why malloc (allocator) guarantees that address return by them will be aligned by 8 byte ( on 32bit machin ) or 16 byte (64 bit machin) ?
4
by: Asm23 | last post by:
Hi i'm using intel P4. when I write the statement like char *p=new char what's the p value, is it aligned by 4 bytes? that's is p%4==0? and, now I'm using the Intel SSE2 instruction to do...
9
by: RichG | last post by:
I'm working with a data stream of 8 bytes in an embedded application. In most cases the data is byte aligned so I can define a structure and then memcpy the data directly to the structure elements. ...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.