• 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

parseInt()

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I compiled the following code and the output is as follows?
Can someone explain why is it so?
__________________________________________________________

public class BinDec{
public static void main(String argv[]){
System.out.println(Integer.parseInt("011",3));
System.out.println(Integer.toString(64,2));
}
}
__________________________________________________________

If you compile and run this program the output will be
4
1000000
CAN SOMEONE EXPLAIN WHY?? if anybody can tell me how do we use parseInt() it will be very helpful...
thanks in advance...
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

In the first statement
System.out.println(Integer.parseInt("011",3));
The output is 4 because you specified a radix/base of 3,
011 = 1*3 + 1 = 4
In the second case
System.out.println(Integer.toString(64,2));
The output is 1000000 because you specified base 2 and 64 in binary is 1000000.
If you want to simply convert to integer, do not put any radix.
I hope this helps.


 
sriram gupta
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi cherry,
thanks for ur help.. cna u tell me where i can read more about this.... i have R&H but i didn't find anything there and i am appearing for paper on this monday...
bye
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi sriram,
The best place to get information on the Math and wrappper classes is straight from the API.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
[This message has been edited by Jane Griscti (edited August 14, 2001).]
reply
    Bookmark Topic Watch Topic
  • New Topic