This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes hexa decimal Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "hexa decimal" Watch "hexa decimal" New topic
Author

hexa decimal

Shiva Mohan
Ranch Hand

Joined: Jan 05, 2006
Posts: 477
class Q {

public static void main(String [] args) {

int x = 0x80000000;
System.out.print(x );
}
}

answer is -2147483648 if we take bit representation of hexa number 800000000 as
1000 0000 0000 0000 0000 0000 0000 0000.

But I always do my calculation like
1000 0000 0000 0000 0000 0000 0000 0000.(here we are just having 28 bits)so the remaning 4 bits are the begginnnig 0�s.

0000 1000 0000 0000 0000 0000 0000 0000 0000.(now the sign bit is positive,since it is positive ,my result is always 2147483648.i end up my calculation like this.)
Please help me.
prashanth kumar
Ranch Hand

Joined: Mar 22, 2004
Posts: 162
do calculation like this..
0x80000000;
0(*)16 pow 0 + 0(*)16 pow 1 + ............. + 8 (*)16 pow 7

Now the total value may exceed 2 pow 31 - 1
And hence it negates..

If i get a question like this,iam going to leave this

Cheers


SCJP1.5(86%)<br />SCWCD1.4(95%)<br />SCBCD1.3(92%)<br />IBM 252
 
 
subject: hexa decimal
 
Similar Threads
Shift operators !
Range related
Different between signs(Positive and Negative ) and values
Shift Operators
Bit Shifting question