• 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
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Character.Min_Radix

 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i found the follwing Q in dan's mock test.What i am unable to understand the effect of 2nd paramerter of valueOF(String s, int radix) method.
Some one plz help me.


class D {
public static void main (String args[]) {
Byte b1 = Byte.valueOf("10",Character.MIN_RADIX);
Byte b2 = Byte.valueOf("10",8);
Byte b3 = Byte.valueOf("10",10);
Byte b4 = Byte.valueOf("10",16);
Byte b5 = Byte.valueOf("10",Character.MAX_RADIX);

System.out.print(b1+","+b2+","+b3+","+b4+","+b5);

}
}


thanx in advance.
regds
Arpana
 
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The radix is the base of the number system. If the radix is 10 then the number is a base 10 representation of a value.
The number 10 in base 8 is represented in decimal as the number 8. The number 10 in base 16 is represented in decimal as 16.
 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dan:
i agree that radix is the base of the number system ... but i fail to understand the following example from the API docs of Integer class parseInt(String s, int radix) method.


parseInt("Kona", 27) returns 411787


/SAmith
 
Arpana Rai
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dan,
can you plz explain that with some nice examples.
thanx
regds
Arpana
 
Dan Chisholm
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Arpana Rai:
Dan,
can you plz explain that with some nice examples.
thanx
regds
Arpana





 
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Originally posted by Samith Nambiar:
parseInt("Kona", 27) returns 411787


Treat this similar to Index 16 - instead use 27.
(K * 27 ^ 3) + (O * 27 ^ 2) + (N * 27 ^ 1) + (A * 27 ^ 0)
For Base-16, we have 0 to 9 and A,B,C,D,E,F for numbers from 10 to 15.
Similarly for Base-27, You'd have numbers from 0 to 9 and then alphabets starting from 'A' representing the numbers from 10 to 26. Alphabet 'R' would represent numeric 26. Therefore you cannot call parseInt() on any string that contains alphabets beyond 'R' using the radix as 27.
For ex: if you change the call as follows:
pasreInt("Sona", 27) --> This should throw an exception.
 
Arpana Rai
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx Dan and Vin for such a nice explanation.

regds
Arpana
 
Samith Nambiar
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Vin i get it now
/SAmith
 
reply
    Bookmark Topic Watch Topic
  • New Topic