C 语言中的位取反操作符 续
前一篇文章的问题,在我查阅了《The C Programming Language》(K&R) 第二版后,发现了如下的定义
在附录A 参考手册的 A.7.4 一元运算符 二进制反码运算符 中有如下表述
一元运算符 ~ 的操作数必须是整型,结果为操作数的二进制反码。在运算过程中需要对操作数进行整形提升。如果操作数为无符号类型,则结果为提升后的类型能够表示的最大值减去操作数的值而得到的结果值。如果操作数为带符号型,则结果的计算方式为:将提升后的操作数转换为相应的无符号类型,使用运算符 ~ 计算反码,再将结果转换为带符号的类型。结果的类型为提升后的操作数类型。
对于整形提升,在附录A 参考手册的 A6.1 整形提升 有如下表述
在一个表达式中,凡是可以使用整形的地方都可以使用带符号或无符号的字符、短整型或整型位字段,还可以使用枚举类型的对象。如果原始类型的所有值都可用 int 类型表示,则其值将被转换为 int 类型;否则将被转换为 unsigned int 类型。这一过程称为整形提升(integral promotion)。
请注意红色标注的句子,“结果的类型为提升后的操作数类型”,意味着 ~(char) 、 ~(short) 等的结果类型都是整型(int)。

Sep 21, 2022 08:33:05 PM
One of the rational and scientific ways to progress is computer science. A rapidly expanding discipline, computer science is now in great demand. For all regional kids enrolled in Central Board schools across the nation, NCERT Computer Question Paper Class 7 the NCERT Computer Sample Paper 2023 Class 7 is provided with all Topic essential questions and suggested answers for download.
Mar 06, 2024 04:40:28 PM
Checking out the information of any celebrity on idol net worth to know how much their name and fame worth and their family members.
Feb 05, 2026 08:31:35 PM
타임케어 출장홈타이 - 출장마사지와 출장안마 홈타이 서비스를 전국 어디서나 24시간 편하게! 전문 마사지사의 맞춤 홈케어로 피로를 빠르게 해소하고 최상의 힐링을 경험하세요. 선입금 없는 후불제 운영으로 더욱 안심!
Feb 05, 2026 09:15:03 PM
오늘 김포출장마사지 김포출장안마. #김포출장마사지 #김포출장안마 #20대관리사 #후불제. 예약문의. 2025년 정상 영업중입니다. 김포출장마사지 김포
Feb 10, 2026 03:12:34 AM
소액결제현금화란 무엇인가? · 소액결제현금화는 휴대폰 소액결제 서비스를 활용해 현금을 확보하는 방법을 말합니다.
Apr 23, 2026 02:52:31 AM
Hey there, this is one excellent content. I appreciate you taking the time to provide this important information. The visitors are constantly drawn in by the quality of the material.
May 10, 2026 09:12:55 AM
I have read your essay a few times since, for the most part, your opinions align with mine. For every reader, there is excellent stuff.
May 22, 2026 04:28:08 AM
I wanted to express my gratitude for this fantastic read! I thoroughly enjoyed every aspect of it. I've saved your website so I can see what fresh content you provide.
Jul 09, 2026 04:23:50 AM
After reading this, I'm pleased by the high caliber of work and insightful ideas. I would want to express my gratitude to the writer and wish you well for attending! Your joy is a breath of fresh air.