Converting byte array (char array) to an integer type (short, int, long)

前端 未结 5 1433
名媛妹妹
名媛妹妹 2020-12-08 11:35

I was wondering if system endianness matters when converting a byte array to a short / int / long. Would this be incorrect to do if the code runs on both big-endian and litt

5条回答
  •  没有蜡笔的小新
    2020-12-08 12:33

    The problem as you've specified, where you are using an existing byte array, will work fine across all machines. You will end up with the same answer.

    However, depending on how you are creating that stream, it may be affected by endianness and you may not end up with the number you think you will.

提交回复
热议问题