• 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

Why does this compile

 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class Test{
public static void main(String args[]){
int i=0xFFFFFFF1;
}
}
since the hex no. is too large to fit into an int shouldn't there be a compile time error?
 
Enthuware Software Support
Posts: 4822
52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is 0xFFFFFFF1 too large for an int? Nope. int is 32 bits and there are 8 hex digits here => 8*4=32 bits.
HTH,
Paul.

------------------
Get Certified, Guaranteed!
(Now Revised for the new Pattern)
www.enthuware.com/jqplus
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The number you gave fits just right into a var of int (32 bits).
You have 7 F plus an one....7*4+4 = 32 bits.
If you add one more F, you will get a compilation error.
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Try this code .You will see the range of
int values and the value of int i=0xFFFFFFF1;(-15).
that is why the code compiles.



Hoping this may help..
Rosemol.
[This message has been edited by Rosemol Thanjappan (edited January 08, 2001).]
 
Michael Burke
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see how you arrived at 4 bits per digit times 8 = 32 which fits into an int. I thought that FFFFFFF1 didn't fit into an int since 7FFFFFFF hex is the largest hex no. of type int according to the jls and FFFFFFF1 is a larger no.
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

hi Micheal
0x7FFFFFFF=2147483647, is the largest POSITIVE integer. but 0xFFFFFFF1 is not larger than 0x7FFFFFFF. In fact it is -15.
This is because the first bit in a 32-bit integer is a sign bit and integers are stored using sign-2's complement method in java.
-AJ
 
Michael Burke
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the replies, Aj I realized that the number was negative after I posted my last message.
 
reply
    Bookmark Topic Watch Topic
  • New Topic