This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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);
}
}

Regards,
Milind

[This message has been edited by Milind Kulkarni (edited July 07, 2000).]
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I was wondering when does thcompiler know it's a negativ number?

Thanks.
 
Jayakumar Thirumalai
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Jay

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic