| 4 | 1/1 | 返回列表 |
| 查看: 785 | 回復(fù): 3 | ||
benchurry銅蟲 (初入文壇)
|
[求助]
c++位操作求助
|
|
《c++ primer》中5.3.1節(jié) bitset_quiz1.set(27); int_quiz1 ▏=1UL<<27; 我的疑惑是第一句顯然是將bitset_quiz1中位置27(從0開始數(shù))的位置為1,但是 1UL<<27就迷惑了,這個(gè)不是將32位表示的二進(jìn)制數(shù)1左移27么,那它就是位置4置為1了(從0開始數(shù))。這兩個(gè)明顯不一樣嘛,我覺得是不是應(yīng)該將 int_quiz1 ▏=1UL<<27;中27改為4?????? |

至尊木蟲 (著名寫手)
驃騎將軍
|
這是定義的那段話 bitset<30> bitset_quiz1; // bitset solution unsigned long int_quiz1 = 0; // simulated collection of bits In the bitset case we can define bitset_quiz1 to be exactly the size we need. By default each of the bits is set to zero. In the case where we use a built-in type to hold our quiz results, we define int_quiz1 as an unsigned long, meaning that it will have at least 32 bits on any machine. Finally, we explicitly initialize int_quiz1 to ensure that the bits start out with well-defined values. 這里是為了說明2個(gè)解決方案,要么用bitset,要么用unsigned long,都可以. 下面是設(shè)置第27個(gè)學(xué)生的成績(都是從右往左數(shù)的) bitset_quiz1.set(27); // indicate student number 27 passed int_quiz1 |= 1UL<<27; // indicate student number 27 passed 第一個(gè)bitset直接.set就可以,注意第二個(gè)是個(gè)簡寫的位或操作(|=),1UL<<27之后,從右往左第27位置1,然后與int_quiz1按位與,可以將int_quiz1的第27位置1,而不影響其他學(xué)生的成績. |

銅蟲 (初入文壇)

新蟲 (小有名氣)
| 4 | 1/1 | 返回列表 |
| 最具人氣熱帖推薦 [查看全部] | 作者 | 回/看 | 最后發(fā)表 | |
|---|---|---|---|---|
|
[考研] 279求調(diào)劑 +12 | j的立方 2026-03-29 | 12/600 |
|
|---|---|---|---|---|
|
[考研] 291求調(diào)劑 +8 | Y-cap 2026-03-29 | 10/500 |
|
|
[考研] 327求調(diào)劑 +5 | 小卡不卡. 2026-03-29 | 5/250 |
|
|
[考研] 311求調(diào)劑 +7 | 藍(lán)月亮亮 2026-03-30 | 7/350 |
|
|
[考研] 085600,專業(yè)課化工原理,320分求調(diào)劑 +5 | 大饞小子 2026-03-29 | 5/250 |
|
|
[考研] 291求調(diào)劑 +8 | HanBeiNingZC 2026-03-24 | 8/400 |
|
|
[考研] 332求調(diào)劑 +6 | @MZB382400 2026-03-28 | 6/300 |
|
|
[考研] 求調(diào)劑 +7 | 青春裁為三截 2026-03-29 | 7/350 |
|
|
[考研] 070305高分子化學(xué)與物理 304分求調(diào)劑 +12 | c297914 2026-03-28 | 12/600 |
|
|
[考研] 343求調(diào)劑 +6 | 愛羈絆 2026-03-29 | 6/300 |
|
|
[考研] 085600,專業(yè)課化工原理,321分求調(diào)劑 +5 | 大饞小子 2026-03-28 | 5/250 |
|
|
[考研] 調(diào)劑考研 +3 | 王杰一 2026-03-29 | 3/150 |
|
|
[考研] 11408軟件工程求調(diào)劑 +3 | Qiu學(xué)ing 2026-03-28 | 3/150 |
|
|
[考研] 394求調(diào)劑 +3 | 好事多磨靜候佳?/a> 2026-03-26 | 5/250 |
|
|
[考研] 330一志愿中國海洋大學(xué) 化學(xué)工程 085602 有讀博意愿 求調(diào)劑 +3 | wywy.. 2026-03-27 | 4/200 |
|
|
[有機(jī)交流]
高溫高壓反應(yīng)求助
10+4
|
chibby 2026-03-25 | 4/200 |
|
|
[考研] 考研調(diào)劑 +10 | 呼呼?~+123456 2026-03-24 | 10/500 |
|
|
[考研] 求調(diào)劑 一志愿 本科 北科大 化學(xué) 343 +6 | 13831862839 2026-03-24 | 7/350 |
|
|
[考研] 289求調(diào)劑 +17 | 碩星赴 2026-03-23 | 17/850 |
|
|
[考研] 【2026考研調(diào)劑】制藥工程 284分 求相關(guān)專業(yè)調(diào)劑名額 +4 | 袁奐奐 2026-03-25 | 8/400 |
|