Results 1 to 6 of 6
- 02-10-2009, 03:32 AM #1
Member
- Join Date
- Feb 2009
- Posts
- 3
- Rep Power
- 0
- 02-10-2009, 03:56 AM #2
Senior Member
- Join Date
- Sep 2008
- Posts
- 564
- Rep Power
- 5
try it first, then we'll help.
- 02-10-2009, 09:38 AM #3
Member
- Join Date
- Feb 2009
- Location
- Italy
- Posts
- 51
- Rep Power
- 0
if you know the math algorithm then it should be easy ;)
but if you have problems with your code post it
- 02-10-2009, 09:41 AM #4
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Take a look at the Integer class and it's toBinaryString() method. ;-)
Edit: Although I'm sure, as this is homework, you are meant to do it on your own.
In any case, give it a try, and as already suggested, post your code if you have problems, we are not, however, going to do it for you, just so you know.Last edited by masijade; 02-10-2009 at 09:43 AM.
- 02-12-2009, 05:29 AM #5
Member
- Join Date
- Feb 2009
- Posts
- 3
- Rep Power
- 0
i've used binarystring but not really the requirement...:
import java.io.*;
public class DecimalToBinary{
public static void main(String args[]) throws IOException{
BufferedReader num = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a decimal value (8 to 256):");
String x = num.readLine();
int i = Integer.parseInt(x);
String bin = Integer.toBinaryString(i);
System.out.println("Binary Equivalent: " + bin);
}
}
it should be the long cut method using functions like this:
function x [args]
args = args.toString();
if (args.length == 0)
return false;
for (var i = 0;i<args.length;i++)
{
if (args.substring(i,i+1) < "0" || args.substring(i, i+1) > "9")
{
return false;
}
}
return true;
}
{
res1 = 999;
args = arg;
while(args>1)
{
arg1 = parseInt(args/2);
arg2 = args%2;
args = arg1;
if(res1 == 999)
{
res1 = arg2.toString();
}
else
{
res1 = arg2.toString()+res1.toString();
}
}
if(args == 1 && res1 != 999)
{
res1 = args.toString()+res1.toString();
}
else if(args == 0 && res1 == 999)
{
res1 = 0;
}
else if(res1 == 999)
{
res1 = 1;
}
var ll = res1.length;
while(ll%4 != 0)
{
res1 = "0"+res1;
ll = res1.length;
}
return res1;
}
{
var sd = name.value;
if(isNum(sd))
{
var result = deciToBin(sd);
document.first.deciBin.value = result;
}
else
{
document.first.deci.value = sd.substring(0,sd.length-1) ;
}
}
- 02-12-2009, 08:17 AM #6
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Please repost your code (from your editor not by copying what you have already posted, as that has already had the formatting ruined) using code tags so the formatting is preserved. That, as it is, is only a pain to attempt to read, and can easily lead to misunderstood code, and, ipso facto, advice.
Similar Threads
-
Binary IO help
By kosok in forum New To JavaReplies: 2Last Post: 12-25-2008, 07:58 AM -
convert a java binary/executable to a intermediate language
By sumit_400461 in forum Advanced JavaReplies: 1Last Post: 07-13-2008, 07:04 PM -
get binary value
By rushenas in forum New To JavaReplies: 2Last Post: 06-14-2008, 01:51 PM -
newbie needs help...
By vicky08 in forum New To JavaReplies: 2Last Post: 03-31-2008, 04:26 PM -
Use recursion to convert binary to...
By coco in forum Advanced JavaReplies: 1Last Post: 08-07-2007, 07:46 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks