Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. class wb{
  2. static int toDecimal(String binary,int i) {
  3. int n = binary.length();
  4. if (i == n-1)
  5. return binary.charAt(i) - '0';
  6. return ((binary.charAt(i) - '0') << (n-i-1)) +
  7. toDecimal(binary, i+1);
  8. }
  9. public static void main(String []args)
  10. {
  11. String binary = "1011100010";
  12. int i=0;
  13. System.out.println(toDecimal(binary,i));
  14. }
  15.  
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement