Re: Converting char->int and int->char. HOW?
From: Kaj Risberg (krisberg_at_welho.com)
Date: 12/04/03
- Next message: Roedy Green: "Re: Converting char->int and int->char. HOW?"
- Previous message: Roedy Green: "Re: Converting char->int and int->char. HOW?"
- In reply to: gajo: "Converting char->int and int->char. HOW?"
- Next in thread: Thomas Schodt: "Re: Converting char->int and int->char. HOW?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 4 Dec 2003 22:49:16 +0200
This should work in java: (similar to c)
int a = 0;
char b = 1;
a = (int) b;
b = (char) a;
Same code in pascal:
VAR a : INTEGER,
b: CHAR;
a := 0; b:=1;
a := ORD(b);
b := CHR(a);
"gajo" <gajo@eunet.yu> kirjoitti viestissä
news:bqnq14$3ot$1@news.eunet.yu...
> In Pascal you have these two functions:
>
> Ord(ch: char): integer; which returns the ASCII number of that char
> Chr(i: integer): char; which returns the character of that ASCII number
>
> How can I do the same in Java? I've found these two functions:
>
> static int getNumericValue(char ch)
> static char forDigit(int digit, int radix)
>
> getNumericValue does not return the correct number. For example, for 'c' I
> get 12, while I should get something like 65 I think.
> I haven't even tested the forDigit function, cause I have no idea what the
> radix is suppoed to be, and the documentation only says that 0 <= digit <
> radix
>
> So what is it I'm supposed to do? How can I have the same two functions in
> Java just like I have them in Pascal?
>
> Also, I've created a HashSet. I want to add a character, but it won't let
> me, and I can only add Strings. This really isn't a problem, but why is it
> so that I cannot add characters to a set?
>
> In Pascal I just type
> s: set of char;
> And it's done. In Java it seems impossible (to me).
>
> Gajo
> ocsabo@neobee.net
>
>
- Next message: Roedy Green: "Re: Converting char->int and int->char. HOW?"
- Previous message: Roedy Green: "Re: Converting char->int and int->char. HOW?"
- In reply to: gajo: "Converting char->int and int->char. HOW?"
- Next in thread: Thomas Schodt: "Re: Converting char->int and int->char. HOW?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|