File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -292,7 +292,7 @@ <h2 id="_1">前言</h2>
292292< blockquote >
293293< p > < img src ="./img/bulb.png " height ="30px " width ="auto " style ="margin: 0; border: none "/> 本书还在持续更新中……要追番的话,可以在 < a href ="https://github.com/parallel101/cppguidebook "> GitHub</ a > 点一下右上角的 “Watch” 按钮,每当小彭老师提交新 commit,GitHub 会向你发送一封电子邮件,提醒你小彭老师更新了。</ p >
294294</ blockquote >
295- < p > 更新时间:2024年11月26日 12:33:25 (UTC+08:00)</ p >
295+ < p > 更新时间:2024年12月17日 11:34:36 (UTC+08:00)</ p >
296296< p > < a href ="https://parallel101.github.io/cppguidebook "> 在 GitHub Pages 浏览本书</ a > | < a href ="https://142857.red/book "> 在小彭老师自己维护的镜像上浏览本书</ a > </ p >
297297< h2 id ="_2 "> 格式约定</ h2 >
298298< blockquote >
Original file line number Diff line number Diff line change @@ -421,7 +421,7 @@ <h2 id="index-_1">前言</h2>
421421<blockquote>
422422<p><img src="../img/bulb.png" height="30px" width="auto" style="margin: 0; border: none"/> 本书还在持续更新中……要追番的话,可以在 <a href="https://github.com/parallel101/cppguidebook">GitHub</a> 点一下右上角的 “Watch” 按钮,每当小彭老师提交新 commit,GitHub 会向你发送一封电子邮件,提醒你小彭老师更新了。</p>
423423</blockquote>
424- <p>更新时间:2024年11月26日 12:33:25 (UTC+08:00)</p>
424+ <p>更新时间:2024年12月17日 11:34:36 (UTC+08:00)</p>
425425<p><a href="https://parallel101.github.io/cppguidebook">在 GitHub Pages 浏览本书</a> | <a href="https://142857.red/book">在小彭老师自己维护的镜像上浏览本书</a></p>
426426<h2 id="index-_2">格式约定</h2>
427427<blockquote>
@@ -19203,6 +19203,15 @@ <h3 id="undef-_9">左移或右移的位数,不得超过整数类型上限,
1920319203i << 0; // 可以
1920419204i << -1; // 错!
1920519205</code></pre>
19206+ <p>但是你还需要考虑一件事情:<strong>隐式转换</strong>,或者直接点说:<strong>整数提升</strong>。</p>
19207+ <ul>
19208+ <li>在 C++ 中算术运算符不接受小于 int 的类型进行运算。如果你觉得可以,那只是隐式转换,整形提升了。</li>
19209+ </ul>
19210+ <pre><code class="language-cpp">std::uint8_t c{ '0' };
19211+ using T1 = decltype(c << 1); // int
19212+ </code></pre>
19213+ <p>即使移位大于等于 8 也不成问题。</p>
19214+ <hr />
1920619215<p>对于有符号整数,左移还不得破坏符号位</p>
1920719216<pre><code class="language-cpp">int i = 0;
1920819217i << 1; // 可以
Load diff Large diffs are not rendered by default.
Original file line number Diff line number Diff line change @@ -583,6 +583,15 @@ <h3 id="_9">左移或右移的位数,不得超过整数类型上限,不得
583583i << 0; // 可以
584584i << -1; // 错!
585585</ code > </ pre >
586+ < p > 但是你还需要考虑一件事情:< strong > 隐式转换</ strong > ,或者直接点说:< strong > 整数提升</ strong > 。</ p >
587+ < ul >
588+ < li > 在 C++ 中算术运算符不接受小于 int 的类型进行运算。如果你觉得可以,那只是隐式转换,整形提升了。</ li >
589+ </ ul >
590+ < pre > < code class ="language-cpp "> std::uint8_t c{ '0' };
591+ using T1 = decltype(c << 1); // int
592+ </ code > </ pre >
593+ < p > 即使移位大于等于 8 也不成问题。</ p >
594+ < hr />
586595< p > 对于有符号整数,左移还不得破坏符号位</ p >
587596< pre > < code class ="language-cpp "> int i = 0;
588597i << 1; // 可以
You can’t perform that action at this time.
0 commit comments