• 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

Integer class's method

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public static String toBinaryString(type val)
public static String toOctalString(type val)
public static String toHexString(type val)
how these methods behave if negative value is passed in them.... i don't know how the output is coming from thee method for negative numbers.....please help....
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you read the Javadocs for java.lang.Integer? Because the descriptions for those methods tell you how they handle negative numbers.
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Best way to get the answer is to try it yourself. If you're still confused, post some snippets of code that you've tried but you don't understand.
 
duhit Choudhary
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Matthew Brown wrote:Have you read the Javadocs for java.lang.Integer? Because the descriptions for those methods tell you how they handle negative numbers.


yes i have seen that.... but still not clear....
 
duhit Choudhary
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Junilu Lacar wrote:Best way to get the answer is to try it yourself. If you're still confused, post some snippets of code that you've tried but you don't understand.


thanks junilu..... i'll definitely try it by myself and then i'll get back....
 
Matthew Brown
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

duhit Choudhary wrote:yes i have seen that.... but still not clear....



"The unsigned integer value is the argument plus 2^32 if the argument is negative; otherwise, it is equal to the argument."

I'm not sure I can explain it more clearly that that. If you call Integer.toHexString(-5), it treats it as Integer.toHexString(2^32 - 5).

Why it does that is related to the way negative numbers are represented in binary. You might want to read about Two's complement.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic