Hey,
I was wondering if someone could explain to me how to put raw bytes into a variable of a specific type.
For example, I have a byte array with 2 elements, 0xFF and 0xFF. I want to put these into an unsigned short, which will equate to the maximum value of a unsigned short, 65535.
I worked out how to do this (google) using a shift and bitwise OR, it works but tbh i don't understand exactly what its doing on a bit level that makes it work.
Ok, with that said I also need to do the same with 8 Bytes -> double and 4 Bytes -> unsigned int, sadly I have no idea how to approach this

Thanks for any help
Jack
I was wondering if someone could explain to me how to put raw bytes into a variable of a specific type.
For example, I have a byte array with 2 elements, 0xFF and 0xFF. I want to put these into an unsigned short, which will equate to the maximum value of a unsigned short, 65535.
I worked out how to do this (google) using a shift and bitwise OR, it works but tbh i don't understand exactly what its doing on a bit level that makes it work.
Code:
unsigned short v = data[0];
v<<8|data[1]; //shift 8 bits & or it
Ok, with that said I also need to do the same with 8 Bytes -> double and 4 Bytes -> unsigned int, sadly I have no idea how to approach this

Thanks for any help
Jack