Originally posted by Barry Brashear:
Not sure I understand. How do convert from char to int as in the following:
char retValue;
retValue = hexConvert( asciiCode[1] ) * 16 + hexConvert( asciiCode[2]
I get an error here.
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?
Layne