%x和意义〜 [英] Significance of %x and ~

查看:151
本文介绍了%x和意义〜的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

int m=32
printf("%x" , ~m);

这句话的输出是 ffdf 并没有输出 20
什么是%X

推荐答案

操作符是按位否定。它会打印按位 M 的价值的否定。 %X 表示的printf 将在十六进制格式输出其价值。

The ~ operator is bitwise negation. It will print bitwise negation of m's value. %x means that printf will output its value in hexadecimal format.

所以,值 0xffdf 是价值 0x20的的否定(32)。

So, value 0xffdf is the negation of value 0x20 (32).

值32(INT位会):

Value 32 (int bits would be):

0000 0000 0010 0000

其位求反将是:

1111 1111 1101 1111

这是有道理的,因为:

Which makes sense since:

1111 1111 = 0xff

1101 1111 = 0xdf

这篇关于%x和意义〜的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆