C function to reverse the byte order in a double?
I'm trying to write an extension to PHP which means coding in C. I'm really really rusty at C coding and was never very good at it.
Can anyone propose an efficient, safe, and [hopefully] future-proof way of reversing a double? Keep in mind that it should work on as many systems as possible and on 32- and 64-bit systems (and on ???-bit systems in the future?). Will the size of a 'double' ever change or will it always be 8 bytes? I've tried this and it doesn't work...the compiler complains about "invalid operands to binary" because I'm trying bitwise shiftw on a non-integer. Code:
x = (x>>56) | |
Quote:
I.e. either case you double to long enough (unsigned) int or use a union whose one field will be your double and the other - long enough (unsigned) int. |
Quote:
Maybe the OP can use it: Code:
#include <stdint.h> |
Well, entering
convert double to network order into Yahoo yields as the very first match: http://www.dmh2000.com/cpp/dswap.shtml . |
All times are GMT -5. The time now is 06:21 AM. |