• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

hexa decimal

 
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic