美文网首页
Java char short 区别

Java char short 区别

作者: mitten | 来源:发表于2016-09-26 21:09 被阅读105次

    Char is unsigned, short is signed.

    So while they are both 2-byte long, they use the sixteenth bit for different purposes.

    The range of the char type is 0 to 2^16 - 1 (0 to 65535).

    The short range is -2^15 to 2^15 - 1 (−32,768 to 32,767).

    stackoverflow相关链接

    char和short在内存中所占大小一样,都是16位。但是short有一位符号位。所以范围是0 ~ 2^16 - 1 (0 ~ 65535)。而char没有符号位。所以char的范围是-2^15 ~ 2^15 - 1 (−32,768 ~ 32,767).

    相关文章

      网友评论

          本文标题:Java char short 区别

          本文链接:https://www.haomeiwen.com/subject/drnqyttx.html