Link to home
Start Free TrialLog in
Avatar of Samooramad
Samooramad

asked on

convert char to int

Hi experts,
how do I do what I named the title of the question? :)
I know there is something like parseInt or something but I need exact syntax
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Samooramad
Samooramad

ASKER

I need to compare them
// (if c == '1')
int i = (int)c - '0';
what if I dont have a positive value for c to compare it with?
I need something liike:
if myclass.getPosition() == the character converted to integer
It depends on how you're treating these chars but say the char is holding a representation of a digit:

char c = '1';
int x = 1;
int y = (int)c - '0';

System.out.println(x == y); // prints true
>>what if I dont have a positive value for c to compare it with?

c couldn't hold a negative value. What values do you want it to hold?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
sorry got cut off.
yes i meant i do want positive values.. that was a typo
objects dont you need to convert it?
You don't - as my first comment shows
A char is a numeric type that just happens to be able to store 'characters'
sorry CEHJ. I didnt understand that was what you meant
thanks
>>sorry CEHJ. I didnt understand that was what you meant

Yes assignment/comparison address the same type conversion issues
thanks objects
8-)