confusion with primitives
posted 16 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
why are the m and n values same??? though we have assigned a -m to n...
saipavan vallabhaneni
Ranch Hand
Posts: 34
posted 16 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
sorry Himanshu,
i didn't understand what you were trying to tell
i got the following output...
i didn't understand what you were trying to tell
1.4E-45 -1.4E-45
-2147483648 -2147483648
-1 1
integer max value: 2147483647
Output completed (0 sec consumed)
i got the following output...
why is n being assigned a -ve value where we assigned -m to n
posted 16 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Hi, check compiling this code.
I think it will clear your doubt.
The Range of byte is -128 - 127.
So it cannot hold a value -b1 which is +128.
I think it will clear your doubt.
The Range of byte is -128 - 127.
So it cannot hold a value -b1 which is +128.
saipavan vallabhaneni
Ranch Hand
Posts: 34
posted 16 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
thanks himanshu and abhi
i understood now
i understood now
posted 16 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
The min value of any integer type is represented at the bit level by the fist bit (the sign bit) being one, and the rest of the bits being 0. This means that:
1000...00 // MIN_VALUE
0111...11 // MIN_VALUE 1's complement
1000...00 // MIN_VALUE 1's complement + 1 = MIN_VALUE 2's complement
So MIN_VALUE and -MIN_VALUE are always the same.
The same is obviously not the case of MAX_VALUE and -MAX_VALUE, since the bit patterns capable of representing negative integers is one more than those capable of representing strictly positive integers.
0111...11 // MAX VALUE
1000...00 // MAX VALUE 1's complement
1000...01 // MAX_VALUE 2's complement
In this case, negating MAX_VALUE will give you what you would expect from a mathematical point of view.
1000...00 // MIN_VALUE
0111...11 // MIN_VALUE 1's complement
1000...00 // MIN_VALUE 1's complement + 1 = MIN_VALUE 2's complement
So MIN_VALUE and -MIN_VALUE are always the same.
The same is obviously not the case of MAX_VALUE and -MAX_VALUE, since the bit patterns capable of representing negative integers is one more than those capable of representing strictly positive integers.
0111...11 // MAX VALUE
1000...00 // MAX VALUE 1's complement
1000...01 // MAX_VALUE 2's complement
In this case, negating MAX_VALUE will give you what you would expect from a mathematical point of view.
All code in my posts, unless a source is explicitly mentioned, is my own.
| For my next trick, I'll need the help of a tiny ad ... Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing |







