Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Dan's Question

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

What is the result of attempting to compile and run the program?
a. Prints: 0000,ffff
b. Prints: 00000000,ffffffff
c. Prints: 7fff,8000
d. Prints: 8000,7fff
e. Prints: 7fffffff,80000000
f. Prints: 80000000,7fffffff
g. Compile-time error
h. Run-time error
i. None of the above
Answer: f
Can someone please explain to me how is 80000000 calculated?
TIA,
-Jarrod
 
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Integer.MIN_VALUE in binary is 1000 0000 0000 0000 0000 0000 0000 0000 since int is 4 byte deep. Each 4 bits comprise one hex digit (from 0000=0 to 1111=F). So, we get 80000000. Hope this helps.
 
Ranch Hand
Posts: 522
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Integer.MIN_VALUE
----------------
Decimal : -2147483648
Binary : 1000 0000 0000 0000 0000 0000 0000 0000
Hexadecimal : 8 0 0 0 0 0 0 0
As you can see every 4 bits in binary is represented by 1 bit in hex, so 1000 becomes 8 and the rest is zero as you can see.
Hope this helps.
 
Jarrod Legion
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Vad and Vicken.
I seriously dunno how I missed out on this one...my brain's stuffed but got to keep going...
-Jarrod
    Bookmark Topic Watch Topic
  • New Topic