RSS

Left-Shift Operator Is Limited?

06 Mar

Why is left-shift operator with 32 result in lower number?

int i = 1;
(i << 0).Dump(); // Result is 1
(i << 1).Dump(); // Result is 2
(i << 2).Dump(); // Result is 3
(i << 3).Dump(); // Result is 8
(i << 10).Dump(); // Result is 1024
(i << 20).Dump(); // Result is 1048576
(i << 30).Dump(); // Result is 1073741824
(i << 31).Dump(); // Result is -2147483648
(i << 32).Dump(); // Result is 1 -> WHY?
Advertisements
 
Leave a comment

Posted by on March 6, 2018 in General

 

Tags: , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
%d bloggers like this: