This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Why does this compile

 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • 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: 4351
39
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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
  • Quote
  • Report post to moderator
Thanks for the replies, Aj I realized that the number was negative after I posted my last message.
 
You ought to ventilate your mind and let the cobwebs out of it. Use this cup to catch the tiny ads:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!