有没有一种方便的方法对大端数据进行算术运算?这是我一直在做的事情(在伪代码中):
main:
unsigned int big_endian_number = 0x12345678;
int multiplier = 7;
unsigned int little_endian_number = reverse_the_bytes(big_endian_number);
little_endian_number = little_endian_number * multiplier;
big_endian_number = reverse_the_bytes(little_endian_number);
这看起来很直接,但冗长且容易出错。一定有更好的方法。