How do I convert a number (as a String) to an array of bytes in Java?
- by user1795595
I'm creating a method specific method for a java project i'm working on.
The UML given specifies the return type to be of static byte[] that accepts the arguments (String, byte)
So far, looks like this:
public static byte[] convertNumToDigitArray(String number, byte numDigits) {
}
This method is supposed to convert a number (as a String) to an array of bytes. The ordering must go from most to least significant digits. For example, if the
number String is “732” then index 0 of the array should contain 7.
The last argument (numDigits) should match the length of the
string passed in.
How do I do this?