Total members 11889 |It is currently Thu Mar 28, 2024 6:45 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





..my problem is it can't read back...it is a decimal to binary conversion, the decimal to binary conversion is OK it will run.. but the binary to decimal its not working sample i input 1010 the result is 1111110010 supposed to be it is a 10...soory for my English


Code:

import java
.util.Scanner;

class binaryLoop {
  public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.println("Please enter Integer");

int number = sc.nextInt();

String bin=bin1(number);


System.out.println("Binary number is: "+number+"    Decimal number: " +  bin);

  }

public static String bin1 (int num)
 {
int sum=1;
int temp=0;
String bin = "";
if (num==2) ;
while (num!=0)
 {
bin=(num%2)+ bin;
 num=num/2;

               }
return bin;
}
}
 





Author:

there is no condition for conversion from binary to decimal , you only wrote a function to convert to decimal to binary.
You will need to write another one to convert from binary to decimal where you will sum multiply of 2 power N (Position in string).

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 2 posts ] 

  Related Posts  to : conversion from binary to decimal numbers as string
 convert binary number to decimal     -  
 add sequence of decimal numbers     -  
 convert string into binary     -  
 .dll conversion     -  
 Number Conversion     -  
 Type Conversion     -  
 convert hexadecimal to decimal     -  
 please get me the following Delphi to Java conversion     -  
 Scale double number using big decimal     -  
 ramp Counter ANALOGUE TO DIGITAL CONVERSION (ADC)     -  



Topic Tags

Java Strings
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com