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

Ranch Hand
Posts: 93
• Number of slices to send:
Optional 'thank-you' note:
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 b2 = Byte.valueOf("10",8);
Byte b3 = Byte.valueOf("10",10);
Byte b4 = Byte.valueOf("10",16);

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

}
}

regds
Arpana

Ranch Hand
Posts: 1865
• Number of slices to send:
Optional 'thank-you' note:
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
• Number of slices to send:
Optional 'thank-you' note:
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
• Number of slices to send:
Optional 'thank-you' note:
Dan,
can you plz explain that with some nice examples.
thanx
regds
Arpana

Dan Chisholm
Ranch Hand
Posts: 1865
• Number of slices to send:
Optional 'thank-you' note:

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

Ranch Hand
Posts: 154
• Number of slices to send:
Optional 'thank-you' note:

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
• Number of slices to send:
Optional 'thank-you' note:
Thanx Dan and Vin for such a nice explanation.

regds
Arpana

Samith Nambiar
Ranch Hand
Posts: 147
• Number of slices to send:
Optional 'thank-you' note:
thanks Vin i get it now
/SAmith

 Be reasonable. You can't destroy everything. Where would you sit? How would you read a tiny ad? a bit of art, as a gift, the permaculture playing cards https://gardener-gift.com