15

备忘:无符号数和有符号数互转公式的证明

 3 years ago
source link: http://blog.tubumu.com/2020/03/03/memo-01/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

备忘:无符号数和有符号数互转公式的证明

2020-03-032020-03-04Memo

无意翻到之前看《深入理解计算机系统》一书时对 2.2.4 节的关于“无符号数和有符号数互转公式的证明” 的手写笔记。比较简单,但也整理一下。

对大多数 C 语言的实现而言,处理同样字长的有符号数和无符号数之间相互转换的一般规则是:数值可能会改变,但是位模式不变。

二、无符号数转有符号数

001.png
图1:原理(注:上图的 x 应该为 u,书上有误。)

002.png
图2:无符号数转有符号数公式

003.png
图3:证明过程

三、有符号数转无符号数

004.png
图4:原理

005.png
图5:有符号数转无符号数公式

006.png

图6:证明过程


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK