big endian vs little endian
i work on a 64 bit intel processor...i was learning about big and little endian and what i understood was that these are byte orderings within a word such that in a 64 bit data, msb will have lowest address in big endian form and the highest address in little endian form...now i have a problem:
I wrote this code to determine whether my processor was little or big endian... I input
0102030405060708 (this is in hex)
and hoped to get 08 and 07 and 06 and... and 01 as answer
but instead got 0 and 25 and 50 and -125 and -13 and 501 and -41 and 66. when I wrote the same code taking 's' as 2 byte(short), the output for 0102 was 2 and 1 (which is in accordance with little endian)...so what went wrong here?
You are storing your input value as a double, which stores the value as a floating point value. Try using a long long instead, which is a 64 bit integer, and should store the value as you expect.
Taking a hex number into a (double) is not likely to do what you expect; it's a floating point value consisting of a base 2 mantissa and exponent. You might find (long) or (long long) to be closer to what you intended.