左移逻辑LT;< [英] Shift Left Logical <<

查看:146
本文介绍了左移逻辑LT;<的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正好我如何做到这一点的C / C ++?
比方说,我想移 INT I 两次的左侧和存储在值˚F

How exactly do I do this in C/C++? Let's say I want to shift int i twice to the left and store the value in f.

F = I<< 2?

f = i << 2 ?

我不需要这样的一个程序或任何东西,我在它的工作原理只是感兴趣。谢谢你。

I don't need this for a program or anything, I'm just interested in how it works. Thanks.

推荐答案

f = i << 2

的变化是在一些位操作的操作非常有用。

Shifts are useful in a number of bit twiddling operations.

这曾经是四乘一个数字的好方法。然而,这些天来,优化编译器往往会照顾你们。

This used to be a great way to multiply a number by four. However, these days, optimizing compilers tend to take care of that for you.

记住,最左边的两个位被丢弃。

Keep in mind that the two leftmost bits are discarded.

这篇关于左移逻辑LT;&LT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆