This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Are you supposed to write this in Java? Or do you need help with your C code? If the later, this is the wrong place to ask such a question since this website is primarily devoted to Java programming. However, there are several message boards here that are have non-Java related topics. This just isn't one of them. You may get more help trying one of the other message boards or another website that is devoted to just C programming.
Everything you have there will work in Java. You just need to wrap the methods in a class and add appropriate access modifiers to each one.
Joined: Dec 06, 2001
Of course, if this isn't a school assignment, you can do it much easier with Integer.parseInt(). There is a version that takes a String with the character representation of the number and an int for the radix (base) to do the conversion.
Joined: Jun 05, 2001
Not sure I understand. How do convert from char to int as in the following:
Is this a homework assignment where you absolutely have to write this method yourself? If not, then you should use Integer.parseInt() as Stefan illustrated above. One advantage of Integer.parseInt() is that it can convert a string of any arbitrary length. ATM, your function can only convert strings with two "digits". It will take a bit more work to modify your code to get the behavior that is already provided by Integer.parseInt().
Unlike C++, Java has many, many pre-written, pre-tested methods that are very, very useful. You should use these wherever possible. If you are interested, you should browse the Java API docs to get a feel for what is available. In fact, learning how to navigate the API docs is a valuable skill.
After examining your code more closely, I have a question: why does asciiToBinary() return a char? Shouldn't this be an int? Perhaps I don't fully understand what you are trying to do in this method. Can you explain in English with some examples of the parameter that is passed in and the expected return value?
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com