Click here to Skip to main content
15,891,204 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
1<<29.what does this mean?
i know its bitwise operation?

What I have tried:

and why is it defined?

1<<29.how this can be biggest integer?
Posted
Updated 27-Sep-18 8:23am

Yes, it's a bit wise operation:
x << y
moves x to the left by y bits.
x  y  x << y  binary
1  1  2       000010 
2  1  4       000100 
1  3  8       001000
...
So
1 << 29
is one moved 29 bits to the left.or if you prefer, a one followed by 29 zeros in binary, or 536,870,912 which is nowhere near the largest possible value in a signed 32 bit integer: 2,147,483,647 or 01111111111111111111111111111111 in binary.
 
Share this answer
 
Comments
Maciej Los 27-Sep-18 14:21pm    
5ed!
Patrice T 27-Sep-18 15:03pm    
Are you usre ?
2  1  4       000100 

I would have expected
1  2  4       000100 
phil.o 28-Sep-18 4:43am    
You are right there is a typo, even if in this case, 2 << 1 == 1 << 2. Half a mistake, so :)
For a 32-bits signed integer, the maximum [positive] value is (1 << 31) - 1 (because 1 << 31 represents the minimum [negative] value), or 2 147 483 647.

For a 32-bits unsigned integer, the maximum value is (1 << 32) - 1 (minimum value being 0), or 4 294 967 295.

Similarly:

For a 64-bits signed integer, the maximum value is (1 << 63) - 1 (because 1 << 63 represents the minimum [negative] value), or 9 223 372 036 854 775 807.

For a 64-bits unsigned integer, the maximum value is (1 << 64) - 1, or 18 446 744 073 709 551 615.

Maybe this will help you understanding binary shifting operations:
Arithmetic shift - Wikipedia[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900