• 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

digit() of Math class????

 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my query is as follows:
char ch1=51
System.out.println(Character.digit(ch1,2));
System.out.println(Character.digit(ch1,8));
though no compile error is generated in this piece of code -1(an int) is printed for the first println statement which according to me should be 3(an int).the second println statement produces the expected result 3(an int).Why is this difference in the output?
waiting for an explanation.
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found this info in JLS .

"20.5.23 public static int digit(char ch, int radix)
Returns the numeric value of the character ch considered as a digit in the specified radix. If the value of radix is not a valid radix, or the character ch is not a
valid digit in the specified radix, then -1 is returned. "
ch in your case is 3 which is not a valid digit for radix 2 which has only 2 digits:0,1
[This message has been edited by sai challa (edited April 11, 2001).]
 
reply
    Bookmark Topic Watch Topic
  • New Topic