Little endian Vs Big endian

后端 未结 5 1550
北海茫月
北海茫月 2021-02-01 10:32

Lets say I have 4Byte integer and I want to cast it to 2Byte short integer. Am I right that in both (little and big endian) short integer will consist of 2 least significant by

5条回答
  •  感情败类
    2021-02-01 11:19

    First of all, you may already know it but let me mention that the size of int is not guaranteed to be 4 bytes and that of short, 2 bytes across all platforms.

    If in your first question you mean something like this:

    int i = ...;
    short s = (short)i;
    

    then yes, s will contain the lower byte(s) of i.

    I think the answer to your second question is also yes; at the byte level the endianness of the system does come into play.

提交回复
热议问题