• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

doubt

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 !
 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I was wondering when does thcompiler know it's a negativ number?

Thanks.
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Blueberry pie is best when it is firm and you can hold in your hand. Smell it. And smell this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic