I have a byte array that has hex values and I initially put those values in a unsigned long.
I am using a 32 bit processor via Ubuntu at the moment. But, i might have to port this program to a 64 bit processor.
now I am aware of strtoul function but since I was able to convert it would any issues via a direct assignment I did not bother with that function. The reason I put it in a unsigned long was because I was thinking about little/big endian issues and so using a register like signed long would just take care of that problem for me regardless of processor. now however, i have been thinking about how my program would work on a 64 bit processor.
since i am on a 32bit processor it might only recognize 32bit long vs a 64 bit processor only recognizing a 64 bit long which would put my signed long array in jeopardy. so, to fix this issue I just made that signed array into long long. Would that address my concerns? or do I need to do something else?
some help and explanation would be appreciated. all my code is in c++.
Instead of using
longorlong longyou should use a typedef likeuint32_t, or something similar, so it can be 32-bits on all platforms, unless this isn’t what you want?It seems you do have a potential problem with endianness though, if you are simply doing:
since the actual value of the bytes when interpreted as an integer will change depending on endianness. There is a good answer on converting endianness here.