Efficiently combining bytes into a long int

Hi,

I'm having problems assembling a set of 4 bytes into a long int. My approach has been this:

    ulong temp;
    temp = (temp << SHIFT_BYTE) | getByte();
    temp = (temp << SHIFT_BYTE) | getByte();
    temp = (temp << SHIFT_BYTE) | getByte();
    temp = (temp << SHIFT_BYTE) | getByte();
    return temp;

But this results in a ton of calls to the long int library shift and logical or routines, which really aren't necessary. My quick and dirty solution has been to code the function in assembly, and just put the bytes in the appropriate "temp+n" bytes that make up temp. I've tried fooling around with unions, but haven't had any luck.

Thanks,
Bob

Parents Reply Children
No data
More questions in this forum