Ted's Blog

Happy coding

unsigned int 与 int 之和

Ted posted @ 2008年8月21日 20:43 in 未分类 with tags unsigned int c , 4961 阅读

面试题:

unsigned int a = 6;

int b = -20;

int c;

(a+b>6)?(c=1):(c=0)

问:

c=?

 

看下面这段:

K & R A.6.5
Arithmetic Conversions
First, if either operand is long double, the other is converted to long double.
Otherwise, if either operand is double, the other is converted to double.
Otherwise, if either operand is float, the other is converted to float.
Otherwise, the integral promotions are performed on both operands; then, if either operand is unsigned long int, the other is converted to unsigned long int.
Otherwise, if one operand is long int and the other is unsigned int, the effect depends on whether a long int can represent all values of an unsigned int; if so, the unsigned int operand is converted to long int; if not, both are converted to unsigned long int.
Otherwise, if one operand is long int, the other is converted to long int.
Otherwise, if either operand is unsigned int, the other is converted to unsigned int.
Otherwise, both operands have type int.

简单翻译如下:
如果任一个操作数是long double, 则另一个要转换为long double
如果任一个操作数是double, 则另一个要转换为double
如果任一个操作数是float, 则另一个要转换为float
此外整数运算符升级对两个操作数都有影响;
如果任一个操作数是unsigned long int, 则另一个要转换为unsigned long int
如果一个操作数是long int, 另一个是unsigned int, 如果long int可以表示结果,则unsigned int要转换为long int;
否则两个都转换为unsigned long int
如果任一个操作数是long int, 则另一个要转换为long int
如果任一个操作数是unsigned int, 则另一个要转换为unsigned int
除此之外,两个操作数都应是int

 

倒数第二句是解本题的关键:

如果任一个操作数是unsigned int, 则另一个要转换为unsigned int

首先将b=-20用补码表示:

20的二进制:

0000 0000 0001 0100

取反:

1111 1111 1110 1011

再加1:

1111 1111 1110 1100

把第一个代表负号的1去掉,

0111 1111 1110 1100

把上面作为unsigned int 是十进制32748

财(a+b)肯定大于6,

则c=1

Avatar_small
auctioneers for char 说:
2019年7月21日 19:56

<!--td {border: 1px solid #ccc;}br {mso-data-placement:same-cell;}--> Security instrument,” “substitute trustee,” and “trustee” have the meanings assigned by Section 51.0001, Property Code.

Avatar_small
Aimbot 说:
2020年5月21日 09:50

Need Best Hacks to Download Visit: <a title="Game Hacks" href="https://downloadaimbothacks.com/">Aimbot Hacks</a> of 2020.

Avatar_small
Aimbot 说:
2020年5月21日 09:51

[url=https://downloadaimbothacks.com/]Aimbot Hacks [/url]

Avatar_small
Aimbot 说:
2020年5月21日 09:53

Need Best Hacks to Download Visit: Aimbot Hacks of 2020.

Avatar_small
ETHENS 说:
2020年8月09日 15:02

Social Welfare Department, Integrated Child Development Services, Bihar has been created by Anganwadi beneficiaries to help send cash to all Integrated Child Development scheme registered beneficiary's bank account in exchange for food and house-to-house rations through Anganwadi centres.The Citizen of Bihar, Those Children, Pregnant women and other candidates who were going to Anganwadi and having food but due to lockdown, they won’t be able to take food. Now they will get money in their Bank Account by Bihar Government. So Bihar Anganwadi Labharthi can apply Online Application form & App link available on icdsonline.bih.nic.in.

Avatar_small
ETHENS 说:
2020年8月14日 13:05

If you want to convert your PDF documents easily, you can go visit https://altoconvertppttopdf.com/about-us right now, and upload your documents there. The website will do all the job for you.

Avatar_small
jasmine 说:
2020年11月21日 16:42

This is one more case of require to update Windows, unconnectedly from this time it is the video drivers. If you’re using an iGPU, use Windows Update. Divide graphic card users (NVIDIA/AMD) should update with their connected program or through their manufacturer’s website. Contact <a href="https://www.helpdeskaustralia.com/blog/netflix-support-number-australia.html">Netflix Support Number Australia</a>.

Avatar_small
Jasmine 说:
2020年11月23日 13:32

Netflix faces a integer of well-financed and pioneering companies like Apple, Amazon and Google, as well as the cable TV providers. The real future of Netflix is its streaming overhaul. It has been doing appealing well extending its library of movies that customers can watch immediately, but it still has work to do. Verne Kopyt off of the New York Times today reports today, however, that its antagonism is stern in this freedom. If you have any issues related in Netflix about then just visit Netflix Contact Number Australia.
https://www.helpdeskaustralia.com/netflix-phone-number.html

Avatar_small
Lagend SEO 说:
2020年11月30日 16:54

Remarkable article, it is particularly useful! I quietly began in this, and I'm becoming more acquainted with it better! Delights, keep doing more and extra impressive! 123 movies

Avatar_small
Lagend SEO 说:
2020年11月30日 21:00

If more people that write articles really concerned themselves with writing great content like you, more readers would be interested in their writings. Thank you for caring about your content. magyar online casino

Avatar_small
Lagend SEO 说:
2020年12月01日 21:20

nice post, keep up with this interesting work. It really is good to know that this topic is being covered also on this web site so cheers for taking time to discuss this! Flocked Christmas tree latest

Avatar_small
Lagend SEO 说:
2020年12月02日 20:56

SEO Company Los Angeles - Are you looking for the best seo company in Los Angeles? Contact SEO Noble in Los Angeles now. We offer digital marketing, social media marketing and SEO marketing. Visit our website now. los angeles seo company

Avatar_small
Lagend SEO 说:
2020年12月03日 17:39

i was just browsing along and came upon your blog. just wanted to say good blog and this article really helped me. lee classical feng shui

Avatar_small
Lagend SEO 说:
2020年12月03日 19:54

Positive site, where did u come up with the information on this posting?I have read a few of the articles on your website now, and I really like your style. Thanks a million and please keep up the effective work. BuyYoutubeViewsIndia

Avatar_small
sophie 说:
2020年12月23日 20:25

Thank a lot. You have done excellent job. I enjoyed your blog . Nice efforts   Smm reseller panel

Avatar_small
sophie 说:
2020年12月28日 23:29

This is a wonderful article, Given so much info in it, These type of articles keeps the users interest in the website, and keep on sharing more ... good luck.  Abstract Canvas Art

Avatar_small
sophie 说:
2021年1月01日 18:48

Really nice and interesting post. I was looking for this kind of information and enjoyed reading this one.  budapest rentals

Avatar_small
UMAIR 说:
2021年1月13日 16:39

If any of you needs help in organizing their ideas for coming up with your own brand, here's the link for the <a href="https://eatmywords.com/star-clients/">website</a> that a lot of professionals were recommending to me. I found out during the course that I really need to learn a lot about this industry.

Avatar_small
UMAIR 说:
2021年1月13日 16:42

If any of you needs help in organizing their ideas for coming up with your own brand, here's the link for the website that a lot of professionals were recommending to me. I found out during the course that I really need to learn a lot about this industry.

Avatar_small
hennessy gummy bears 说:
2021年2月27日 15:17

They're produced by the very best degree developers who will be distinguished for your polo dress creating. You'll find polo Ron Lauren inside exclusive array which include particular classes for men, women.

Avatar_small
bürogemeinschaft 说:
2021年3月09日 19:34

I am impressed by the information that you have on this blog. It shows how well you understand this subject.

Avatar_small
zarabianie youtube 说:
2021年3月11日 23:45

Cool stuff you have got and you keep update all of us.

Avatar_small
Hatta Tour Dubai 说:
2021年7月01日 18:31

The eagerly awaited EXPO 2020 is at long last occurring. The super occasion that was booked to occur in 2020 (henceforth, the name EXPO-2020) was delayed to this year on account of the pandemic. Nonetheless, presently with antibodies accessible and things glancing positive in the emirate, the occasion is at last going to begin from October 2021 and it will end on March 31, 2022.
<a href="https://www.dubaieveningsafari.com/12-places-to-visit-when-youre-visiting-dubai-for-expo-2020/">Visitng Dubai for Expo 2020</a>

Avatar_small
Arham Malik 说:
2021年9月19日 05:57

<a href="https://desertsafarisabudhabi.com/">Desert Safari Abu Dhabi</a> is one of the leading tour operator companies in the UAE that takes great care of the comfort and convenience of the guests while ensuring that this excursion becomes the most memorable trip of their life. We offer VIP Desert Safari Deals In Abu Dhabi that are true amalgamation of comfort, luxury, extravagance and adventure.

Avatar_small
dark web/deep web/d 说:
2022年8月04日 18:53

Many web sites and pages are made with JavaScript code that is hidden. This means that your computer can only see a part of the web sites that you are trying to access.   dark web links

Avatar_small
dark web/deep web/d 说:
2022年8月04日 19:38

By having an advertising campaign on your website, you can expose yourself and your company to serious financial danger.  deep web

Avatar_small
dark web/deep web/d 说:
2022年8月04日 19:53

Just because you don't have to take the risk of exposing your identity to strangers on the Internet doesn't mean that you shouldn't use these valuable resources responsibly. dark web links

Avatar_small
dark web/deep web/d 说:
2022年8月04日 20:15

For instance, I have friends who are avidly participating in chat rooms as well. It seems that there is no end to the dark web activities that people are engaging in.  dark web sites

Avatar_small
dark web/deep web/d 说:
2022年8月04日 20:30

It's possible to make a lot of money with bitcoins, especially if you combine this opportunity with a bit of skill. The more you know about the dark web, the more profitable it will be for you.   dark web

Avatar_small
dark web/deep web/d 说:
2022年8月04日 20:46

Chia does point out some good pointers as to why some niches are much easier to promote than others, and you will want to make sure that you take advantage of those opportunities.  work from home jobs

Avatar_small
dark web/deep web/d 说:
2022年8月04日 21:03

It wasn't really the product itself; instead, it was their willingness to partner with others in the weight-loss niche that made the partnership so valuable.  affiliate marketing success

Avatar_small
best internet provid 说:
2023年2月02日 22:49

Your work is very good and I appreciate you and hopping for some more informative posts.

Avatar_small
johny 说:
2023年2月07日 02:50 Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info. imr 4198
Avatar_small
collagen tablets 说:
2023年2月20日 03:16

Nice post mate, keep up the great work, just shared this with my friendz

Avatar_small
johny 说:
2023年3月05日 21:32

Nice post! This is a very nice blog that I will definitively come back to more times this year! Thanks for informative post. Bokep

Avatar_small
johny 说:
2023年3月19日 19:24 Very interesting information, worth recommending. However, I recommend this: alien labs carts
Avatar_small
HughesNet 说:
2023年3月24日 06:19

Thanks so much for sharing this awesome info! I am looking forward to see more postsby you!

Avatar_small
dot tire codes 说:
2023年4月11日 05:36

It is a great website.. The Design looks very good.. Keep working like that!.

Avatar_small
SEO 说:
2023年4月13日 20:26

The most interesting text on this interesting topic that can be found on the net ... บาคาร่า 888

Avatar_small
solar ribbon 说:
2023年4月21日 04:00

Wow, What a Excellent post. I really found this to much informatics. It is what i was searching for.I would like to suggest you that please keep sharing such type of info.Thanks

Avatar_small
internet providers T 说:
2023年4月26日 00:58

The reference you've got published is absolutely beneficial. The sites you have referred turned into pleasing. thank you for sharing.

Avatar_small
SEO 说:
2023年4月27日 16:36

In this particular article, you will see a summary, satisfy browse this post. NEW SOUTH WALES FAKE DRIVER LICENCE

Avatar_small
best internet provid 说:
2023年5月07日 20:39

I forward you to scan this theme it is enjoyable described ...

Avatar_small
modular homes 说:
2023年7月06日 02:54

This is certainly additionally an exceedingly wonderful offer everyone truly qualified on the lookout with. It's always not likely everyday there is chances read a little something.

Avatar_small
jsimitseo 说:
2024年1月30日 21:57

Your writings regarding this matter are right, perceive how I composed this site is extremely great.  concierge doctor


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter