知识卡片

普通读书笔记卡 · 10880.a · 生成模型:未记录

补码决定有符号范围

理解等级:初级

N 位整数一共能表示 2^N 种位模式。uN 把它们解释为 0 到 2^N−1。iN 用补码解释同样的位模式,范围是 −2^(N−1) 到 2^(N−1)−1。例如 8 位分别是 0 至 255 和 −128 至 127。有符号范围在负侧多一个值,因此对最小负数取相反数可能溢出。

关联阅读:[[显式选择整数溢出策略]]。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)》第02章《Fundamental Types》|整数的范围、写法与方法解析,来源项目 `book-source`,`extracted/Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)/_epub-src/OEBPS/ch02.xhtml#integer-types` - 结论依据:原文用表格对照有符号、无符号数范围,强调同一组位模式通过补码获得正负值。 - 原始内容:use the two’s complement representation, using the same bit patterns as the corresponding unsigned type to cover a range of positive and negative values (Table