3的反码为什么是-4? - shawpinlee

3的反码为什么是-4?

shawpinlee posted @ 2007年9月17日 06:41 in C/C++ , 3339 阅读

问题:3的反码为什么是-4?

#include <stdio.h>

int main(int argc, char *argv[])
{
        unsigned char a = 3;

        printf("%d\n",~a);

        return 0;
}

结果为-4

分析:

1.数值在内存中以补码形式表示。

2.正数的原码、反码、补码形式上都是相同的;因此,3(unsigned char)的原码、反码、补码为以下:

00000011 (原码)

00000011 (反码)

00000011(补码,内存中的存在形式)

3. 如何求一个负数的补码:将该数的绝对值的二进制形式,按位取反再加1。以-4为例:

(1)4的原码:00000100

(2)取反:111111011

(3)再加1:11111100 (得-4的补码,-4在内存中的存在形式)

4. 对3取反码~3,即是对内存中的3(00000011)取反为11111100,即是-4在内存中的表现形式,输出来即为-4.

============================================================

gcc -S neg.c 经过反汇编后:

 

.file "neg.c"
.section .rodata
.LC0:
.string "%d\n"
.text
.globl main
.type main, @function
main:
leal 4(%esp), %ecx
andl $-16, %esp
pushl -4(%ecx)
pushl %ebp
movl %esp, %ebp
pushl %ecx
subl $36, %esp
movb $3, -5(%ebp)
movzbl -5(%ebp), %eax
notl %eax
movl %eax, 4(%esp)
movl $.LC0, (%esp)
call printf
movl $0, %eax
addl $36, %esp
popl %ecx
popl %ebp
leal -4(%ecx), %esp
ret
.size main, .-main
.ident "GCC: (GNU) 4.1.2 (Ubuntu 4.1.2-0ubuntu4)"
.section .note.GNU-stack,"",@progbits

按位取反,在底层是通过not指令实现的,运算的操作针对的是内存中3的补码形式

============================================================

来自《C语言参考手册》Fith Edition的说明:

一元运算符~对操作数按位取反
bitwise-negation-expression:

    ~ case-expression

操作数可以是任何整形类型。由于不同实现可能对带符号整数使用不同表示方法,因此对带符号操作数采用按位取反运算符~的结果可能无法移植。为了得到可移植的代码,建议只对无符号操作数采用按位取反运算符~。

Avatar_small
VigRX Plus Review 说:
2019年12月09日 21:21

操作数可以是任何整形类型。

Avatar_small
https://royalcbd.com 说:
2020年4月08日 16:19

Spot up with this write-up, I seriously think this site requirements additional consideration. I’ll more likely once again to study additional, many thanks for that information.

Avatar_small
caitlindavidson 说:
2020年5月31日 00:33

Now, I think we all know why they're called <a href="https://buytiktoklikes.uk/">buy TikTok fans</a> - because they look like a toy like a snake. This is not an attempt to sell you a product, as it's been around for a long time.

Avatar_small
caitlindavidson 说:
2020年5月31日 00:34

Now, I think we all know why they're called [url=https://buytiktoklikes.uk/]buy tiktok fans[/url]

- because they look like a toy like a snake. This is not an attempt to sell you a product, as it's been around for a long time.

Avatar_small
india visa 说:
2020年6月11日 20:29

I was perusing a portion of your substance on this site and I imagine this web page is extremely enlightening! Continue setting up.

Avatar_small
cek merek dagang 说:
2020年6月15日 20:00

We have sell some products of different custom boxes.it is very useful and very low price please visits this site thanks and please share this post with your friends.mmmzml a:x:A

Avatar_small
Buy weed online Aust 说:
2020年6月18日 18:48

Looking for a safe and secure place where there is a weed or kush online? Cali weed 420 Shop offered the solution to your problem. You can buy weed online, buy cannabis online,buy most strains of marijuana online from us and get a safe and discreet delivery.

Avatar_small
Chapewerken 说:
2020年6月20日 17:11

Really nice and interesting post. I was looking for this kind of information and enjoyed reading this one. Keep posting. Thanks for sharing.

Avatar_small
Ramen en deuren 说:
2020年6月22日 16:11

Really appreciate this wonderful post that you have provided for us.Great site and a great topic as well i really get amazed to read this. Its really good.

Avatar_small
Chape 说:
2020年6月23日 14:40

I am a new user of this site so here i saw multiple articles and posts posted by this site,I curious more interest in some of them hope you will give more information on this topics in your next articles.

Avatar_small
Bitcoin 说:
2020年6月27日 18:25

Thanks for choosing an opportunity to examine this, I feel incredible about it and love concentrating more on this theme. It is incredibly useful for me. Thanks for such significant assistance once more.

Avatar_small
How Did 说:
2020年6月28日 18:26

Thanks for sharing this information. I really like your blog post very much. You have really shared a informative and interesting blog post with people..

Avatar_small
먹튀 说:
2020年7月10日 15:14

It means to take away the profits of others without paying the price of others' own things. It is short for “eat and splash” and it means to run away with just your own interests. <a href="https://mt-times.com/">먹튀</a>

Avatar_small
먹튀검증 说:
2020年7月10日 17:50

From May 2016, we are the NO.1 gluttony verification community that always strives to create a fair betting culture that is no longer gluttonous for users who believe in and visit mutky commerce from May 2016. . Also, as Much-Tours Commerce does not unilaterally recommend indiscriminate betting sites, it recommends to users so that there will be no accidents in advance based on thorough inspection work. We are pleased to inform you that we are at Muktu Commerce.

Avatar_small
Orthopedic in Islama 说:
2020年7月18日 19:31

<a href="https://medcityhospital.pk/">Orthopedic in Islamabad</a>
We provide the patient with five-star treatment, in the best environment and the most pleasant possible to make his stay more comfortable and less stressful.

Avatar_small
Woofer Guy 说:
2020年7月19日 15:34

Really nice and interesting post. I was looking for this kind of information and enjoyed reading this one. Keep posting. Thanks for sharing.

Avatar_small
backlinks 说:
2020年7月20日 20:22

For this purpose, they use different marketing strategies in which digital marketing is considered to be having a very distinctive position. 

Avatar_small
link building 说:
2020年7月25日 19:51

Domain Authority(DA)Page Authority is a holistic score and difficult to influence directly. It is made up of an aggregate of metrics that each have an impact on the score.

Avatar_small
Woofer GuyBedroom co 说:
2020年7月29日 16:48

I feel very grateful that I read this. It is very helpful and very informative and I really learned a lot from it.

Avatar_small
Bedroomcomfy 说:
2020年7月29日 16:50

After reading your article I was amazed. I know that you explain it very well. And I hope that other readers will also experience how I feel after reading your article.

Avatar_small
parc central residen 说:
2020年7月30日 19:26

I finally found great post here.I will get back here. I just added your blog to my bookmark sites. thanks.Quality posts is the crucial to invite the visitors to visit the web page, that's what this web page is providing.

Avatar_small
parc central residen 说:
2020年8月03日 16:03

Great post! I am actually getting ready to across this information, is very helpful my friend. Also great blog here with all of the valuable information you have. Keep up the good work you are doing here.

Avatar_small
Reiki 说:
2020年8月05日 14:37

After reading your article I was amazed. I know that you explain it very well. And I hope that other readers will also experience how I feel after reading your article.

Avatar_small
Aluminium ramen 说:
2020年8月06日 17:27

This is my first time i visit here. I found so many entertaining stuff in your blog, especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the leisure here! Keep up the good work. I have been meaning to write something like this on my website and you have given me an idea.

Avatar_small
נערות ליווי בחיפה 说:
2020年8月11日 03:30

Girls Whatsup Number
for more info visit:

Avatar_small
Inland Empire Bridal 说:
2020年8月11日 17:49

Actually I read it yesterday but I had some thoughts about it and today I wanted to read it again because it is very well written.

Avatar_small
how to lose weight f 说:
2020年8月19日 02:57

I surmise I have chosen an intelligent and mind blowing website with interesting material.

Avatar_small
backlinks 说:
2020年8月23日 16:26

High Metrics Niche Related Blog Comments is very latest service which we are giving away to our clients.

Avatar_small
seo backlinks 说:
2020年8月23日 16:27

PageRank (PR) is an algorithm used by Google Search to rank websites in their search engine results. PageRank was named after Larry Page,One of the founders of Google. PageRank is a way of measuring the importance of website pages.

Avatar_small
sasa 说:
2020年9月10日 19:18

Thank you for this fascinating post, I am happy I observed this website on Google. Not just content, in fact, the whole site is fantastic. wordpress free themes download

Avatar_small
sasa 说:
2020年9月17日 19:50

I recently came across your blog and have been reading along. I thought I would leave my first comment. I don't know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often. telenor golden numbers

Avatar_small
Webdesign 说:
2020年9月26日 23:13

Thank you for your post, I look for such article along time, today i find it finally. this post give me lots of advise it is very useful for me.

Avatar_small
Webdesign 说:
2020年9月28日 18:10

It has fully emerged to crown Singapore's southern shores and undoubtedly placed her on the global map of residential landmarks. I still scored the more points than I ever have in a season for GS. I think you would be hard pressed to find somebody with the same consistency I have had over the years so I am happy with that.

Avatar_small
farhan 说:
2020年10月01日 00:22

Thank you very much for this great post. Satta King

Avatar_small
Webdesign 说:
2020年10月01日 19:15

Excellent Blog! I would like to thank for the efforts you have made in writing this post. I am hoping the same best work from you in the future as well. I wanted to thank you for this websites! Thanks for sharing. Great websites!

Avatar_small
jemes 说:
2020年10月05日 16:03

Rinmaru having the big collection of different creature’s game.
<a href="https://rinmarugames.org/">rinimarut</a>

Avatar_small
Read More 说:
2020年10月05日 16:43

Do you have any tips and pieces of information for longing creators? I'm needing to start my own site soon yet I'm to some degree lost on everything.

Avatar_small
ibmseo 说:
2020年10月05日 19:11

These websites are really needed, you can learn a lot. frozen yogurt

Avatar_small
Lambingan 说:
2020年10月05日 19:15

yes, i am the complete truly contemplating this text, and that i simply reason say that this article is the entire beneficial and enlightening. I in conjunction with have some panicky fragment of concerned info !!!!!!thank you.

Avatar_small
Bigg Boss 14 说:
2020年10月07日 15:40

thanks totally a great deal for the sharing! COOL..

Avatar_small
ibmseo 说:
2020年10月08日 21:13

Great post! I am actually getting ready to across this information, is very helpful my friend. Also great blog here with all of the valuable information you have. Keep up the good work you are doing here. 먹튀검증

Avatar_small
안전놀이터 说:
2020年10月13日 19:09

Thank you for your submit and also fantastic suggestions.. also My partner and i furthermore believe work will be the main aspect of acquiring accomplishment.

Avatar_small
bestluggagesetstoday 说:
2020年10月17日 15:08

Such a very useful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article.

Avatar_small
토토사이트 说:
2020年10月21日 04:36

Many thanks with regard to supplying current improvements concerning the issue, We anticipate study much more.

Avatar_small
SEO 说:
2020年10月21日 15:32

I wanted to thank you for this great read!! I definitely enjoying every little bit of it I have you bookmarked to check out new stuff you post.

Avatar_small
Webdesign 说:
2020年10月22日 17:39

You might comment on the order system of the blog. You should chat it's splendid. Your blog audit would swell up your visitors. I was very pleased to find this site.I wanted to thank you for this great read!!

Avatar_small
Webdesign 说:
2020年10月24日 17:00

I will really appreciate the writer's choice for choosing this excellent article appropriate to my matter.Here is deep description about the article matter which helped me more.

Avatar_small
farhan 说:
2020年10月27日 20:42

I really appreciate the kind of topics you post here. Thanks for sharing us a great information that is actually helpful. Good day! 먹튀폴리스

Avatar_small
Click here 说:
2020年10月28日 20:35

The extraordinary site you arrived! It would be ideal if you continue refreshing, I will def read more. It'll be in my bookmarks so better update! <a href='https://santacruzmovingasso.wixsite.com/movingassocruz'>Click here</a>

Avatar_small
farhan 说:
2020年10月29日 19:09

I’m going to read this. I’ll be sure to come back. thanks for sharing. and also This article gives the light in which we can observe the reality. this is very nice one and gives indepth information. thanks for this nice article... 토토사이트

Avatar_small
Click here 说:
2020年10月29日 21:46

Howdy! An obligation of appreciation is all together for the tremendous information you have given! You have addressed crucial centers! <a href='https://pleasantonmovingasso.wixsite.com/moversassociation'>Click here</a>

Avatar_small
Click here 说:
2020年10月31日 18:48

I visit your blog often and endorse it to the individuals who expected to improve their knowledge without any problem. The way of creating is splendid and moreover, the substance is a decision. An obligation of appreciation is all together for that astuteness you give the peruses.

Avatar_small
visit this link 说:
2020年10月31日 21:53

I am uncommonly happy to discover your post as it will be on top of my get-together of most cherished destinations to visit.

Avatar_small
Read more 说:
2020年11月02日 16:37

Hey, you used to compose awesomely, yet the last scarcely any posts have been kind of exhausting… I miss your extraordinary works. Past a few posts are slightly out of track! please!

Avatar_small
Click here 说:
2020年11月02日 22:10

I have as of late began a blog, the data you give on this webpage has helped me enormously. A debt of gratitude is in order for the entirety of your time and work.

Avatar_small
visit this website 说:
2020年11月03日 15:54

This is really respectable and instructive, containing all information moreover extraordinarily influences the new development. An obligation of appreciation is all together for sharing it, <a href='https://fremontmovingasso.wixsite.com/sanfranassociation'>visit this website</a>

Avatar_small
Elelive 说:
2020年11月04日 18:32

Just saying thanks will not just be sufficient, for the fantasti c lucidity in your writing. I will instantly grab your rss feed to stay informed of any updates.

Avatar_small
토토사이트 说:
2020年11月07日 23:52

For many people this is important, so check out my profile:

Avatar_small
gloryhole swallow jo 说:
2020年11月09日 18:34

I just got to this amazing site not long ago. I was actually captured with the piece of resources you have got here. Big thumbs up for making such wonderful blog page!

Avatar_small
farhan 说:
2020年11月12日 14:01

Thank you because you have been willing to share information with us. we will always appreciate all you have done here because I know you are very concerned with our. 먹튀검증

Avatar_small
slots and games 说:
2020年11月15日 18:49

It’s very informative and you are obviously very knowledgeable in this area. You have opened my eyes to varying views on this topic with interesting and solid content.

Avatar_small
farhan 说:
2020年11月16日 15:11

You completed a number of nice points there. I did a search on the issue and found nearly all people will have the same opinion with your blog. 먹튀검증

Avatar_small
Top SEO 说:
2020年11月24日 08:11

New web site is looking good. Thanks for the great effort. CBD Bud

Avatar_small
commission host oto 说:
2020年11月24日 22:04

You actually make it look so easy with your performance but I find this matter to be actually something which I think I would never comprehend. It seems too complicated and extremely broad for me. I'm looking forward for your next post, I’ll try to get the hang of it!

Avatar_small
안전놀이터 说:
2020年11月25日 01:25

I actually enjoy the posting. It usually is wonderful to evaluate any one demonstrate around thoughts in the cardiac coupled with lucidity in this significant dilemma can be immediately found.

Avatar_small
Robinjack 说:
2020年11月26日 17:32

He is also a Cornell University graduate with a PhD in statistics, a fact which lends to his credibility and competence in making a system like Sports Betting Champ.   link 12bet

Avatar_small
Robinjack 说:
2020年11月26日 17:32

Who will verify the legality of such companies? Do they operate as a singular firm or do they operate as a syndicate and group of sport gambling companies? There are some gambling businesses that operate as a value chain and some operate as a single company.   bet88

Avatar_small
Robinjack 说:
2020年11月28日 20:35

In usual practice sport gambling is done through legal bookmakers who exist in large numbers in different parts of the world.   1gomgom

Avatar_small
Robinjack 说:
2020年11月28日 20:35

Georgia Lottery is one of the biggest lotteries of the world with a social mission to responsibly maximize revenues for the educational programs they fund.   sxmb

Avatar_small
Robinjack 说:
2020年11月29日 23:43

There are companies that give you sports betting tips, but you should not follow them blindly.   1gom.com

Avatar_small
Robinjack 说:
2020年11月30日 16:55

I seriously loved this post. You describe this topic adequately. When hiring home contractors it’s critical for go with a trusted name in construction. Experienced and efficient staff should shoot for excellence and absorb every detail of your dwelling. www.fast7k.com reviews

Avatar_small
Robinjack 说:
2020年12月01日 22:13

Thats why over 90% of people who place bets during the season will lose their money.   fb88.com

Avatar_small
Robinjack 说:
2020年12月02日 18:02

In gambling, when you lose, its time to either stop or up your bets in order to make up for lost funds. fun120fun88

Avatar_small
Robinjack 说:
2020年12月02日 18:02

This is your connection to all the horse races, the football matches or any other sports betting action there might be on; and you can roam the brightly lit gambling atrium playing the slot machines or anything else, all while you keep in touch with your sports bet.   m88link

Avatar_small
Robinjack 说:
2020年12月02日 21:51

The shifting continued up to the very end and it is said that half of the handle came from New York City.   nhacaivn88

Avatar_small
see more 说:
2020年12月08日 18:44

Hi. I have perused the greater part of your posts. This post is likely where I got the most valuable data for my examination.

Avatar_small
jacksonseo 说:
2020年12月20日 19:22

Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained! poetry sad love

Avatar_small
Robinjack 说:
2020年12月21日 19:26

I like your website.. great shades & motif. Performed people design and style this fabulous website yourself or even have people rely on someone else to make it work for you personally? Plz interact when I!|m looking to pattern by myself blog site plus would want to find out wherever u received this particular through. thank you reservation software online

Avatar_small
jacksonseo 说:
2020年12月23日 23:37

Very efficiently written information. It will be beneficial to anybody who utilizes it, including me. Keep up the good work. For sure i will check out more posts. This site seems to get a good amount of visitors. mollie abrechnung

Avatar_small
Pak24tv 说:
2020年12月26日 14:04

I am happy to find your distinguished way of writing the post. Now you make it easy for me to understand and implement the concept. Thank you for the post. types of government summary meaning 4 pillars of democracy Pak24tv

Avatar_small
Hemp Bombs CBD gummi 说:
2020年12月27日 22:28

It is perfect time to make some plans for the future and it is time to be happy. I've read this post and if I could I desire to suggest you some interesting things or suggestions. Perhaps you could write next articles referring to this article. I want to read more things about it!

Avatar_small
jacksonseo 说:
2020年12月29日 19:29

I was just browsing through the internet looking for some information and came across your blog. I am impressed by the information that you have on this blog. It shows how well you understand this subject. Bookmarked this page, will come back for more. Swimmingpool 

Avatar_small
LEGEND SEO 说:
2020年12月29日 20:40

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! movies 123

Avatar_small
LEGEND SEO 说:
2020年12月31日 19:52

Superior post, keep up with this exceptional work. It's nice to know that this topic is being also covered on this web site so cheers for taking the time to discuss this! Thanks again and again! 123movies

Avatar_small
Tree service near me 说:
2021年1月16日 19:46

Efficiently written information. It will be profitable to anybody who utilizes it, counting me. Keep up the good work. For certain I will review out more posts day in and day out.<a href="https://ayalaslandscaping.com/">Tree service near me</a>

Avatar_small
Plumbers bristol 说:
2021年1月17日 19:13

A very awesome blog post. We are really grateful for your blog post. You will find a lot of approaches after visiting your post.<a href="https://www.a1plumbersbristol.co.uk/">Plumbers bristol</a>

Avatar_small
a1plumbersbristol 说:
2021年1月17日 19:21

Efficiently written information. It will be profitable to anybody who utilizes it, counting me. Keep up the good work. For certain I will review out more posts day in and day out.<a href="https://g.page/A1plumbersbristol?share">a1plumbersbristol</a>

Avatar_small
Best Motorcycle Jack 说:
2021年1月17日 19:35

A number of dissertation websites on the internet for those who purchase needless to say publicised as part of your page. <a href="https://www.zensleather.com/">Best Motorcycle Jackets Online</a>

Avatar_small
Admit Card 说:
2021年1月18日 21:16

JNVST Class 9 exams are scheduled to be held on 13th February 2021 and NVS Admit Card 2021 for Class 9 is expected to release in January 2021 tentatively. Whereas JNV Class 6 exams are scheduled to be held on 10th April 2021 and 6th Class JNVST Roll Number 2021 is expected to release in March 2021. Since the JNVST exams will be conducted for Class 6 and Class 9, will also be released separately we will provide you with all the necessary information regarding Navodaya Vidyalaya Admit Card for Class 6 and Class 9. Read on to find out more.
https://jnanabhumiap.in/jnvst-admit-card-navodaya-6th-hall-ticket-download/

Avatar_small
john sasda 111 说:
2021年1月19日 01:55

I read a article under the same title some time ago, but this articles quality is much, much better. How you do this.. 토토사이트

Avatar_small
John 111 说:
2021年1月27日 02:54

Awesome blog. I enjoyed reading your articles. This is truly a great read for me. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work! 먹튀검증


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter
Host by is-Programmer.com | Power by Chito 1.3.3 beta | © 2007 LinuxGem | Design by Matthew "Agent Spork" McGee