4
单目操作符(含原码反码补码转换)
source link: https://blog.51cto.com/u_15740457/5562129
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.
单目操作符(含原码反码补码转换)
原创单目运算符是指运算所需变量为一个的运算符,即在运算当中只有一个操作数,又叫一元运算符。
~ 例子如下
输出结果为-1
int定义的变量是有符号的,int=signed int,两者完全等价,此处省略了signed。unsigened定义的数字没有正负之分,所以Unsigned定义的数全是正数。
因为前面是int定义,所以最高位指的是符号位,1为负,0为正。又因为负数在内存中存储的时候,存储的是二进制的补码。而我们打印/使用的是这个数的原码。
原码,反码,补码的计算规则:
原码到反码:符号位不变,其余取反。
反码到补码:反码+1得到补码。
++ -- 例子如下
总结:不管前置或者后置,a都需要进行加减。但计算b时,若后置,则“后知后觉”,b不变;若前置,则与a相同!
(类型)强制类型转换····不建议 例子如下
- 1赞
- 1收藏
- 评论
- 分享
- 举报
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK