青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

好吧,我被征服了—— 關于 c++ unsigned char

1 unsigned char i;
2 i=-20;
3 
上面一段很簡單的代碼,如果輸出會是什么 呢?
今天群里的新學c++同學問我,unsighed char 和char 有啥區別,上面的輸出會有什么 不同
在這里,我先鄙視一下自己,我直觀的理解為通常的 首位符號位,然后丟下的就是輸入無符號的。好吧,估計各位看官說我太菜,但確實是輸出的結果和我想的不大一樣,如果各位沒明白我說的是什么問題,可以試一下。然后回來看下面的內容。












。

In an unsigned type, all the bits represent the value. If a type is defined for a particular machine to use 8 bits, then the unsigned version of this type could hold the values 0 through 255.

無符號型中,所有的位都表示數值。如果在某種機器中,定義一種類型使用 8 位表示,那么這種類型的 unsigned 型可以取值 0 到 255。

The C++ standard does not define how signed types are represented at the bit level. Instead, each compiler is free to decide how it will represent signed types. These representations can affect the range of values that a signed type can hold. We are guaranteed that an 8-bit signed type will hold at least the values from 127 through 127; many implementations allow values from 128 through 127.

C++ 標準并未定義 signed 類型如何用位來表示,而是由每個編譯器自由決定如何表示 signed 類型。這些表示方式會影響 signed 類型的取值范圍。8 位 signed 類型的取值肯定至少是從 -127 到 127,但也有許多實現允許取值從 -128 到 127。

Under the most common strategy for representing signed integral types, we can view one of the bits as a sign bit. Whenever the sign bit is 1, the value is negative; when it is 0, the value is either 0 or a positive number. An 8-bit integral signed type represented using a sign-bit can hold values from 128 through 127.

表示 signed 整型類型最常見的策略是用其中一個位作為符號位。符號位為 1,值就為負數;符號位為 0,值就為 0 或正數。一個 signed 整型取值是從 -128 到 127。

Assignment to Integral Types
整型的賦值

The type of an object determines the values that the object can hold. This fact raises the question of what happens when one tries to assign a value outside the allowable range to an object of a given type. The answer depends on whether the type is signed or unsigned.

對象的類型決定對象的取值。這會引起一個疑問:當我們試著把一個超出其取值范圍的值賦給一個指定類型的對象時,結果會怎樣呢?答案取決于這種類型是 signed 還是 unsigned 的。

For unsigned types, the compiler must adjust the out-of-range value so that it will fit. The compiler does so by taking the remainder of the value modulo the number of distinct values the unsigned target type can hold. An object that is an 8-bit unsigned char, for example, can hold values from 0 through 255 inclusive. If we assign a value outside this range, the compiler actually assigns the remainder of the value modulo 256. For example, we might attempt to assign the value 336 to an 8-bit signed char. If we try to store 336 in our 8-bit unsigned char, the actual value assigned will be 80, because 80 is equal to 336 modulo 256.

對于 unsigned 類型來說,編譯器必須調整越界值使其滿足要求。編譯器會將該值對 unsigned 類型的可能取值數目求模,然后取所得值。比如 8 位的 unsigned char,其取值范圍從 0 到 255(包括 255)。如果賦給超出這個范圍的值,那么編譯器將會取該值對 256 求模后的值。例如,如果試圖將 336 存儲到 8 位的 unsigned char 中,則實際賦值為 80,因為 80 是 336 對 256 求模后的值。

For the unsigned types, a negative value is always out of range. An object of unsigned type may never hold a negative value. Some languages make it illegal to assign a negative value to an unsigned type, but C++ does not.

對于 unsigned 類型來說,負數總是超出其取值范圍。unsigned 類型的對象可能永遠不會保存負數。有些語言中將負數賦給 unsigned 類型是非法的,但在 C++ 中這是合法的。


In C++ it is perfectly legal to assign a negative number to an object with unsigned type. The result is the negative value modulo the size of the type. So, if we assign 1 to an 8-bit unsigned char, the resulting value will be 255, which is 1 modulo 256.

C++ 中,把負值賦給 unsigned 對象是完全合法的,其結果是該負數對該類型的取值個數求模后的值。所以,如果把 -1 賦給8位的 unsigned char,那么結果是 255,因為 255 是 -1 對 256 求模后的值。



When assigning an out-of-range value to a signed type, it is up to the compiler to decide what value to assign. In practice, many compilers treat signed types similarly to how they are required to treat unsigned types. That is, they do the assignment as the remainder modulo the size of the type. However, we are not guaranteed that the compiler will do so for the signed types.

當將超過取值范圍的值賦給 signed 類型時,由編譯器決定實際賦的值。在實際操作中,很多的編譯器處理 signed 類型的方式和 unsigned 類型類似。也就是說,賦值時是取該值對該類型取值數目求模后的值。然而我們不能保證編譯器都會這樣處理 signed 類型。



以上摘自 c++ primer,慚愧,還是再細細的從頭品一次這書吧。









posted on 2011-02-13 16:12 Brandon 閱讀(4974) 評論(0)  編輯 收藏 引用 所屬分類: C++

<2025年9月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

導航

統計

常用鏈接

留言簿(2)

隨筆分類

隨筆檔案

文章分類

文章檔案

收藏夾

IT WEB

常用鏈接

牛人BLOG

學習網站

搜索

積分與排名

最新評論

閱讀排行榜

評論排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            在线免费观看日本一区| 欧美成人一二三| 亚洲精品乱码久久久久| 免费不卡欧美自拍视频| 亚洲人成网站在线播| 在线一区二区三区做爰视频网站| 国产精品一区二区欧美| 欧美福利视频在线观看| 欧美视频日韩视频| 麻豆av福利av久久av| 欧美久久久久久久久久| 久久精品夜色噜噜亚洲a∨| 欧美国产激情二区三区| 欧美一区二区免费视频| 欧美成人精品不卡视频在线观看| 亚洲欧美日韩精品久久| 开心色5月久久精品| 亚洲欧美在线网| 欧美国产日产韩国视频| 久久人人97超碰精品888| 欧美午夜视频在线观看| 亚洲东热激情| 尤物精品国产第一福利三区| 中日韩在线视频| 日韩视频免费在线观看| 久久久国产精品一区二区中文| 日韩亚洲国产精品| 久久久综合精品| 午夜综合激情| 欧美精品三级| 麻豆成人小视频| 国产日韩欧美精品| 一区二区三区视频在线观看 | 一本一本大道香蕉久在线精品| 亚洲一区日本| 日韩午夜激情电影| 老色鬼精品视频在线观看播放| 久久成人在线| 国产乱码精品| 午夜精品亚洲一区二区三区嫩草| 亚洲在线中文字幕| 欧美日韩一区二区高清| 亚洲日韩欧美视频| 日韩亚洲视频| 欧美日韩精品免费观看| 亚洲精品视频一区二区三区| 亚洲欧洲一区二区三区久久| 狼狼综合久久久久综合网 | 欧美午夜激情在线| 亚洲精品一区在线| 日韩午夜在线| 欧美精品v日韩精品v韩国精品v| 欧美韩国一区| 91久久久亚洲精品| 欧美精品在线观看91| 亚洲人成网站影音先锋播放| 日韩午夜高潮| 国产精品久久久久久亚洲调教 | 亚洲毛片在线观看| 欧美日韩国产在线播放| av成人免费在线| 亚洲欧美日韩一区| 国产欧美综合在线| 久久精品一区二区| 亚洲第一精品夜夜躁人人躁| 亚洲精品资源| 国产精品地址| 欧美一区二区成人6969| 美国三级日本三级久久99| 伊人狠狠色j香婷婷综合| 免费在线观看精品| 99在线精品视频在线观看| 午夜在线电影亚洲一区| 国产视频一区欧美| 久久亚洲精品视频| 日韩小视频在线观看专区| 亚洲一区999| 国产亚洲欧洲| 欧美黄色视屏| 午夜亚洲性色福利视频| 欧美高清在线精品一区| 亚洲色在线视频| 国产在线精品二区| 欧美激情亚洲| 欧美伊久线香蕉线新在线| 亚洲激情第一页| 欧美一区二区三区免费视| 免费观看在线综合| 一本色道久久综合亚洲91| 久久精品国产久精国产一老狼| 国产日本欧美一区二区| 欧美成人自拍| 欧美亚洲一区三区| 亚洲日本久久| 久久午夜av| 亚洲在线成人| 最新高清无码专区| 国产欧美 在线欧美| 欧美大秀在线观看| 欧美在线你懂的| 一本色道久久综合狠狠躁的推荐| 久热精品在线视频| 亚洲欧美综合网| 亚洲人成在线观看一区二区| 国产精品爽爽爽| 欧美电影专区| 久久精品网址| 亚洲欧美日韩国产综合精品二区| 亚洲二区在线观看| 久久免费偷拍视频| 午夜精品福利在线| 一区二区三区欧美激情| 亚洲国产精品一区二区www| 国产日韩欧美视频| 欧美视频在线观看视频极品| 欧美 日韩 国产精品免费观看| 欧美亚洲尤物久久| 亚洲男人的天堂在线| 日韩视频中午一区| 亚洲国产裸拍裸体视频在线观看乱了中文 | 亚洲国产成人porn| 狂野欧美性猛交xxxx巴西| 亚洲一区二区三区精品在线| 亚洲人成亚洲人成在线观看| 尤物九九久久国产精品的分类| 国产乱子伦一区二区三区国色天香 | 亚洲免费播放| 极品尤物av久久免费看| 国产欧美精品日韩区二区麻豆天美| 欧美日本国产| 欧美激情精品久久久久久蜜臀| 老鸭窝毛片一区二区三区| 久久久久久网址| 久久久天天操| 另类尿喷潮videofree| 久久青草欧美一区二区三区| 久久福利一区| 久久久亚洲高清| 久久综合九色综合网站| 老司机午夜精品视频| 久久综合国产精品台湾中文娱乐网 | 一区二区三区成人 | 亚洲美女黄色| 日韩亚洲国产欧美| 亚洲色图综合久久| 在线亚洲免费| 午夜精品理论片| 欧美一区二区视频97| 久久精品视频va| 噜噜噜久久亚洲精品国产品小说| 久久理论片午夜琪琪电影网| 亚洲人精品午夜| 国产精品视频免费观看| 国产精品自拍小视频| 国产亚洲在线| 亚洲高清不卡| 一区二区久久久久久| 亚洲欧美日韩国产| 久久免费黄色| 亚洲国产99| 夜久久久久久| 性欧美大战久久久久久久免费观看 | 国产欧美一区在线| 极品日韩av| 夜夜嗨av一区二区三区中文字幕 | 欧美激情综合亚洲一二区| 欧美日产一区二区三区在线观看| 欧美日韩国产限制| 国产女主播在线一区二区| 在线观看欧美激情| 一区二区三区日韩欧美| 久久av一区二区| 欧美国产极速在线| 一本色道久久综合亚洲精品小说 | 亚洲在线观看视频| 久久久欧美精品| 亚洲啪啪91| 午夜精品剧场| 免费亚洲电影在线观看| 国产精品久久久久久久9999| 激情综合网激情| 亚洲香蕉网站| 欧美91福利在线观看| 中文欧美在线视频| 蜜臀av国产精品久久久久| 国产精品久久婷婷六月丁香| 亚洲国产三级网| 久久激情一区| 夜夜嗨av一区二区三区网站四季av | 国产亚洲在线观看| 一本色道久久综合亚洲91| 久久久久天天天天| 一本久久青青| 欧美福利专区| 在线成人h网| 欧美一区二区三区在线| 最新国产成人在线观看| 久久久xxx| 国产精品综合视频| 亚洲一区二区免费看|