In addition to Weibo, there is also WeChat
Please pay attention

WeChat public account
Shulou
2025-10-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains the "pit example analysis of bit operation in C language". The content of the explanation in this article is simple and clear, and it is easy to learn and understand. let's study and learn the pit example analysis of bit operation in C language.
For example, the following example:
Short a = 0xBC54; / / binary is: 1011 1100 0101 0100short b = 0x07A3; / / binary is: 0000 0111 1010 0011if ((a | b) = = 0xBFF7) {/ / 0xBFF7 binary is: 10111111 1111 0111 puts ("true");} else {puts ("false");}
Will the program print "true" or "false"?
The answer is "false".
Because there is a rule in the bit operation of C language, if the length of the Operand is less than "signed/unsigned int", it will convert the Operand to "signed/unsigned int" and then perform the bit operation. In the above code, when you perform the "a | b" operation, it is actually a "((int) a) | ((int) b)" operation. The type of the expression "a | b" is actually "int", and the value in the above code is 0xFFFFBFF7.
In the above code, if the type of an and b is "unsignedshort", then the program will print "true" because the "a | b" operation is actually a "((unsigned int) a) | (unsigned int) b)" operation.
Thank you for your reading. the above is the content of "the pit example analysis of bit operation in C language". After the study of this article, I believe you have a deeper understanding of the pit example analysis of bit operation in C language. the specific use of the situation also needs to be verified by practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope





About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.