Reputation: 43
How am I to convert a char into its numerical encoding value?
The code I used is
public class Q1A {
int toInt(char character){
int getInt = toInt(character);
return getInt;
}
}
Sorry if my question is hard to understand
Upvotes: 0
Views: 224
Reputation: 35587
you just need
int toInt(char character){
int i = (int) character; // this will gives int value(ASCII) of char.
return i;
}
Or you can simplify to
int toInt(char character){
return (int) character;
}
You can use Character.getNumericValue(c)
too to get numeric value . More about Character.getNumericValue(c)
Upvotes: 1
Reputation: 100
Do you mean the ASCII value of a char?
int toInt(char character) {
return (int)character
}
Upvotes: 0
Reputation: 10552
It depends on if you want to actual numeric value of the char or the ascii value or somthing similar
//Get numeric value
int toInt(char c)
{
return Character.getNumericValue(c);
}
//Get ascii value
int toInt(char c)
{
return (int)c;
}
Upvotes: 0