Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

binary representation

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I'm trying to solve this question from Dan's topic exam.

class B {
public static void main(String args[]) {
System.out.print(Integer.toHexString(Integer.MIN_VALUE)+",");
System.out.print(Integer.toHexString(Integer.MAX_VALUE));
}
}
What is the result of attempting to compile and run the program?
**************************
Is there a shortcut way to know the bit format of Integer.MIN_VALUE instead of determining it by , repeated division of smallest integer value by 2.
also, what is the bit representation of Integer.MIN_VALUE?
Thanks in advance

Sharda.
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An integer has thirty-two bits. It uses two's compliment notation where the leftmost bit is the signed bit. The smallest number an integer can represent is a "1" in the sign bit and the rest zeros:
10000000000000000000000000000000
The largest number an integer can represent:
01111111111111111111111111111111
So I guess the shortcut is knowing the number of bits the number type can hold. For example, I know a byte has eight bits, so I know Byte.MIN_VALUE is:
10000000
And Byte.MAX_VALUE is:
01111111

Dan C. has a good tutorial on this and also changing them to Hex:
Dan's Tutorial
 
Sharda R Govindu
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thankyou Larry, That helps!!
 
reply
    Bookmark Topic Watch Topic
  • New Topic