• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • 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!!
 
You showed up just in time for the waffles! And this tiny ad:
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
reply
    Bookmark Topic Watch Topic
  • New Topic