• 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

int assignment

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
int i1 = 0xffffffff

The max range for integer variables is 0x7fffffff and min range is 0x80000000.

The above assignment is beyond this range. But how is this a valid assignment. I was expecting a compilation error, but was surprised to see that compiles with no errors.

Can someone explain why this is a valid statement and how would we evaluate the value of i1?
 
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
int are 32 bits signed integers, ok ?

So in hex format, int range is from 0x00000000 to 0xffffffff

Positives int values are in range 0x00000000 to 0x7fffffff
Negatives int values are in range 0x80000000 to 0xffffffff

0xffffffff is the biggest negative int, so it's -1.
 
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,


Try this...
 
reply
    Bookmark Topic Watch Topic
  • New Topic