+ 1

Anybody please explain this code.

cout<<(2<<4<<3); Its output is 256 how?

12th Feb 2019, 6:09 AM
ALI HYDER
ALI HYDER - avatar
3 Answers
+ 10
Above statement is equivalent to the below statement. cout << ((2 << 4) << 3); Left shifting is done from left to right first. 2 is left shifted 4 times which results in 32. Then 32 is left shifted 3 times which results in 256.
12th Feb 2019, 6:22 AM
blACk sh4d0w
blACk sh4d0w - avatar
+ 2
There "<<" in brackets is binary shift 2 << 4 2 equals 10 in binary This operation do it like this: 000010->100000 Those operations has very low priority, so they program just makes this like: ((2<<4)<<3) 2<<4 is 32 32<<3 is 256(000100000->100000000)
12th Feb 2019, 6:21 AM
Дмитрий Мазыло
Дмитрий Мазыло - avatar
0
Better search "binary operations c++", I can't describe this properly I just can say that (1<<n) is 2 in power of n
12th Feb 2019, 6:22 AM
Дмитрий Мазыло
Дмитрий Мазыло - avatar