如何使用左移分配算子?它是如何工作的? [英] How to use left-shift assignment operator ? How does it works?

查看:56
本文介绍了如何使用左移分配算子?它是如何工作的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我来到了MSDN运营商(C#参考)。

但是我无法完成这项工作。当操作员将数字向左移动4

时,如本例所示。它如何产生16000的输出?谢谢。



资料来源: http://msdn.microsoft.com/en-us/library/ayt2kcfb(v = vs.90).aspx [ ^ ]



class MainClass9

{

static void Main()

{

int a = 1000;

a<< = 4;

Console.WriteLine(a);

}

}

/ *

输出:

16000

* /

解决方案

因为左移二进制数乘以2,例如

 00000101B(=  5 )左移变为00001010B(=  10 



因此,左移数字四次乘以 16


I have come accross the MSDN Operator (C# Reference).
But i am not able to get the working of this. When the operator is shifting a digit to left by 4
as in this example . How it is possible that it produces output of 16000 ? Thanks.

Source : http://msdn.microsoft.com/en-us/library/ayt2kcfb(v=vs.90).aspx[^]

class MainClass9
{
static void Main()
{
int a = 1000;
a <<= 4;
Console.WriteLine(a);
}
}
/*
Output:
16000
*/

解决方案

Because left shifting a binary number multiplies it by two, e.g.

00000101B (=5) left shifted becomes 00001010B (=10)


Hence, left shifting a number four times multiplies it by 16.


这篇关于如何使用左移分配算子?它是如何工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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