aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes confusion with primitives Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "confusion with primitives" Watch "confusion with primitives" New topic
Author

confusion with primitives

saipavan vallabhaneni
Ranch Hand

Joined: Nov 14, 2008
Posts: 34

why are the m and n values same??? though we have assigned a -m to n...
Himanshu Gupta
Ranch Hand

Joined: Aug 18, 2008
Posts: 598

Try so see output of following code. You will get the reason.



My Blog SCJP 5 SCWCD 5
saipavan vallabhaneni
Ranch Hand

Joined: Nov 14, 2008
Posts: 34
sorry Himanshu,
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
Abhi vijay
Ranch Hand

Joined: Sep 16, 2008
Posts: 509
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.
saipavan vallabhaneni
Ranch Hand

Joined: Nov 14, 2008
Posts: 34
thanks himanshu and abhi

i understood now
Ruben Soto
Ranch Hand

Joined: Dec 16, 2008
Posts: 1032
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.


All code in my posts, unless a source is explicitly mentioned, is my own.
 
I agree. Here's the link: jrebel
 
subject: confusion with primitives
 
Similar Threads
this #2
plz tell me about my prolem?
Constructor
Need explanations of inheritance
I am new to Java programming