什么是“<<" C ++中的运算符? [英] What is the "<<" operator in C++?

查看:104
本文介绍了什么是“<<" C ++中的运算符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白运算符<<"是什么在以下代码中表示.

I couldn't understand what does the operator "<<" means in the following code.

    long hashString(char* key)
 {
   int n = strlen(key);
   long h = 0;
   for(int i=0; i<n; i++)
     {
        h = (h << 2) + key[i];
     }
  return abs(h % tablesize);
 }

推荐答案

它是左移运算符.它将值左移2位,有效地将其乘以2乘以2的幂(移位量).

It's the left shift operator. It shifts the value left by 2 bits, effectively multiplying it with 2 to the power of 2 (the shift amount).

a << b

与以下相同:

a * (2 to the power of b)

这篇关于什么是“&lt;&lt;" C ++中的运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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