Hi,
i have problem about how to convert byte to int.
i don't know how to do anymore, because the value of x is 49, that is represent the ascii code.
Here the output:
First character: 1
Number 49 : null

what i want is:
First character: 1
Number 1 : a
Here is my code. Someone plz, help me.

IS the line
Number 49 : null printing ???? coz the if(x >=0 && x<=6) loop does not satisfy the condition...

and by the way wat are you trying to achieve by int x = (int)ch;????

and how are u planning to use x??

happy coding

warm regards
Vinod M

12-02-2010, 11:08 AM

masijade

The OP wants the character "1" to be an integer 1 and the cast, of course, is returning the ascii value of "1" which is 49, see my post.

12-02-2010, 11:13 AM

JosAH

Quote:

Originally Posted by arieana

Hi,
i have problem about how to convert byte to int.
i don't know how to do anymore, because the value of x is 49, that is represent the ascii code.
Here the output:
First character: 1
Number 49 : null

what i want is:
First character: 1
Number 1 : a
Here is my code. Someone plz, help me.

How big is your array 'numbers'? If x == 49 (you typed a '1') note that the if condition near the end of your code fails.

kind regards,

Jos

12-02-2010, 11:16 AM

Vinod Mukundan

Quote:

Originally Posted by masijade

The OP wants the character "1" to be an integer 1 and the cast, of course, is returning the ascii value of "1" which is 49, see my post.

Ya I got it .... I thought he wanted it from the array ...... well still the print

Number 49 : null

wont come ..

yeah of-course your solution should do the trick ..:)

12-02-2010, 02:00 PM

arieana

sorry2 my mistake..
actually output :
First character: 1

that output came out when i replace if(x >=0 && x<=49)
First character: 1
Number 49 : null

12-02-2010, 02:02 PM

masijade

Okay? I kinda figured that, already. So, does it work now?

12-02-2010, 02:06 PM

arieana

i just want the value of x is 1 not 49.

12-02-2010, 02:07 PM

masijade

Okay? And did you read the first post?

12-02-2010, 02:10 PM

arieana

yup.

is it like this?
int x = Integer.parseInt(String.valueOf(ch));

when i print value of x, it still =49

12-02-2010, 02:18 PM

masijade

Post the actual code in that area because as long "ch" is a char (or a byte) and not an int it definately will result in the int value 1 for the character/string "1", which means you are doing something else wrong (maybe casting to an int or some such).