How do I convert between big-endian and little-endian values in C++?

前端 未结 30 2572
难免孤独
难免孤独 2020-11-21 23:18

How do I convert between big-endian and little-endian values in C++?

EDIT: For clarity, I have to translate binary data (double-precision floating point values and 3

30条回答
  •  时光说笑
    2020-11-22 00:01

    i like this one, just for style :-)

    long swap(long i) {
        char *c = (char *) &i;
        return * (long *) (char[]) {c[3], c[2], c[1], c[0] };
    }
    

提交回复
热议问题