Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
109 views
in Technique[技术] by (71.8m points)

<< operator in C++?

I am new to C++, what's the exact meaning for the << in statement below, Thanks.

if (Val & (0x0001 << 0))
{}
else
{}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It is a shift-left operation. If you have:

a << b

where a and b are integral types (char, short, long, etc.), then the bits in a are shifted left b places with zeroes filling in on the right. In other words, a is multiplied by 2^b.

Example:

12 << 3

12 (decimal) = 00001100 (binary)

shift left 3 places:

00001100 becomes 01100000 

which is 96 (which is 12 * 8 or 12 * 2^3)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...