Ask Your Question
1

<< operator

asked 2013-04-09 05:10:20 -0600

Nesbit gravatar image

I saw something like this in some source files of OpenCV:

(double)(1<<16)

What does the operator << do?

Thanks.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
5

answered 2013-04-09 06:55:31 -0600

berak gravatar image

in this case it's a binary shift, 1 gets bitwise shifted to the left.

(1 << 16) === (2 ** 16) === pow(2,16) = 65536


but beware, the << and the >> operators are overloaded multiple times (e.g for io)

cout << "l2l2l2";

int n; cin >> n;


or for special operations, as in here:

Mat dm = (Mat_<double>(2,2) << 1.0, 0.0, 3.0, -1.0); // 2x2 double mat with initaialization list

edit flag offensive delete link more

Comments

Thanks a lot ! :D

Nesbit gravatar imageNesbit ( 2013-04-09 07:18:19 -0600 )edit

More exactly, a << b means a*2^b. (http://en.wikipedia.org/wiki/Binary_shift#Bit_shifts)

Nesbit gravatar imageNesbit ( 2013-04-09 07:29:09 -0600 )edit
0

answered 2013-04-09 05:32:42 -0600

updated 2013-04-09 07:00:19 -0600

Actually it depends from case to case. It is an operator that can be specified for each type of input it gets. I know for example that it can be used to effectively retrieve a frame from a capture.

Mat frame;
capture >> frame;

This calls internally the function

capture.read();

No idea what this operator does exactly in this case. But it could be something like creating an array of double elements running from 1 -> 16?

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-04-09 05:10:20 -0600

Seen: 863 times

Last updated: Apr 09 '13