运算符<<在这条线上吗? [英] What does operator << do in this line?

查看:99
本文介绍了运算符<<在这条线上吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白这行是做什么的:

I can not understand what this line does:

fBuffer[fByteIndex] += 1 << (fBitIndex - 1);

其中:

unsigned char fBuffer[32];
int fBitIndex;

和:

for ( int i = 0; i < 32; i++ )
     fBuffer[i] = 0;

fBitIndex = 8;

那里是什么<<?

推荐答案

<<是左移运算符,并且假设fBitIndex是8,则代码

<< is the left-shift operator, and assuming fBitIndex is 8 the code

fBuffer[fByteIndex] += 1 << (fBitIndex - 1);

等同于

fBuffer[fByteIndex] += 128;

为什么?因为左移意味着您将值"left"的位移位;在您的情况下,00000001(1)向左移动7次,成为10000000(128).

Why? Because a left-shift means you shift the bits of the value "left"; in your case, 00000001 (1), is shifted left 7 times, becoming 10000000 (128).

这篇关于运算符&lt;&lt;在这条线上吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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