Hello, I want to construct an applet using JBuilder 4 that can convert decimal numbers into binary numbers and vice-versa. I have been using the following code that I'm able to compile without errors but it doesn't work. Can anyone tell me what I'm doing wrong? Thank you in advance and forever.
Welcome to JavaRanch! First: Please review The JavaRanch Naming Policy and change your display name. Second: This code won't compile. So, let's review some of the most apparent errors:
After these corrections are made, and the program will compile, what error messages are you seeing? These often provide very useful information regarding a problem. Also, I'd recommend a review of Sun's Code Conventions for the Java Language. Good Luck. [ April 18, 2002: Message edited by: Dirk Schreckmann ]
Hi, Dividing the number by two won't get the job done. You will be better off starting from the formula
2^n = # Knowing this we can easily see that a loop such as:
will fill in the StringBuffer with the correct number of ones and zeros. To fit this into your code:
The reverse is left to the student ... Regards, Manfred.
posted 18 years ago
You guys are amazing! I have to admit that when I posted my problem I thought that no one would reply but I couldn't have been more wrong. Learning Java has been a nightmare for me(as you can tell from my lousy coding). I was about to give up on it but the information and people on this site are so helpful that I'm going to stick with it. I will try out the suggested codes. To all those who posted, thanks a bunch!
posted 18 years ago
Hello everyone! I just wanted to let you all know that I was finally able to get my decimal to binary converter applet to work! Hooray! I couldn't have done it without a lot of help and although I still dislike Java I would like to share the code, just in case someone else is suffering with this problem. Thanks again to Mr. Schreckman and Mr. Leonhardt for your posts. Here's the correct code: