The moose likes Beginning Java and the fly likes doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "doubt" Watch "doubt" New topic


Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
can anyone tell me how to find the decimal equivalent
of a -ve hexadecimal no i.e for int i=0x80400000

Thanks !
Milind Kulkarni
Ranch Hand

Joined: Jun 01, 2000
Posts: 146
This simple program will give you result in the decimal form.
class Test {
public static void main (String [] args) {
int i = 0x80400000;
System.out.println (i);


[This message has been edited by Milind Kulkarni (edited July 07, 2000).]
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Thanks for the reply.Actually, i have run the program.Its
giving output as -2143289344.But, when i calculated i got
as -4194304.Hope i am clear.
ricky gonzalez
Ranch Hand

Joined: Jun 30, 2000
Posts: 167
Hi, I was wondering when does thcompiler know it's a negativ number?

Jayakumar Thirumalai

Joined: Jul 08, 2000
Posts: 15
MSB (Most significant bit) is sign bit - am I correct?
if so, in 0x80400000 MSB is 1 which makes it negative.
(negative numbers are stored in one's complement (or is two's).
So, while calculating value from the given hexadecimal number, you should take care of this)
For example, if you change the value to 0x40400000,
the value is 1077936128 which is not a negative number.
int is signed. So, it can hold negative values.
int Minimum value is -2,147,483,648
int Maximum value is 2,147,483,647
Another example, if you change the value to 0x80000000
the value is -2,147,483,648. This clearly shows that MSB is the sign bit.
Try with 0x7FFFFFFF.
the value is 2,147,483,647. This is the maximum value you can store in int.
I hope this makes it clear.

Jayakumar Thirumalai
I agree. Here's the link:
subject: doubt
It's not a secret anymore!