Suppose you have a 32-bit system :
The INT_MAX would be 01111111111111111111111111111111 and INT_MIN would be 10000000000000000000000000000000. 0 & 1 in most-significant bit position representing the sign bit respectively.
Computing INT_MAX and INT_MIN In C/C++ :
The number 0 is represented as 000…000(32 times).
- We compute the NOT of 0 to get a number with 32 1s. This number is not equal to INT_MAX because the sign bit is 1, i.e. negative number.
- Now, a right shift of this number will produce 011…111 which is INT_MAX.
- INT_MIN is NOT of INT_MAX.
0 should be taken as unsigned int.
If 0 is signed, during Step 2, right shift of 111..111 will yield 111…111. This is because arithmetic right shift preserves the sign of the number.
In Java, we have the feature of logical right shift available to us.
INT_MAX 2147483647 INT_MIN -2147483648
Asked in : Google
This article is contributed by Rohit Thapliyal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Bitwise right shift operators in Java
- Russian Peasant (Multiply two numbers using bitwise operators)
- Bitwise Operators in C/C++
- Check if a number is multiple of 9 using bitwise operators
- Euclid's Algorithm when % and / operations are costly
- Sum of Bitwise And of all pairs in a given array
- Bitwise and (or &) of a range
- What are the differences between bitwise and logical AND operators in C/C++?
- Numbers whose bitwise OR and sum with N are equal
- Case conversion (Lower to Upper and Vice Versa) of a string using BitWise operators in C/C++
- Toggle case of a string using Bitwise Operators
- Replace every element of the array with BitWise XOR of all other
- Minimum bitwise operations to convert given a into b.
- Bitwise Sieve
- Check if a number is divisible by 17 using bitwise operators