H
Hostos
how would I convert character objects to their octal representation
according to the ASCII table?
Please help
according to the ASCII table?
Please help
how would I convert character objects to their octal representation
according to the ASCII table?
Gordon Beaton <[email protected]> said::On 9 Sep 2003 07:45:51 -0700, Hostos wrote:
:> how would I convert character objects to their octal representation
:> according to the ASCII table?
:
: Integer.toString(int i, int radix)
:
:/gordon
I won't contest whether this works, since I haven't tried to use it.
But the OP did say "character objects". If we assume that means
character (char) primitives, that should be:
Character.digit(char ch, int radix)
Gordon Beaton <[email protected]> said::On Tue, 09 Sep 2003 10:12:08 -0500, Steve W. Jackson wrote:
:> I won't contest whether this works, since I haven't tried to use it.
:> But the OP did say "character objects". If we assume that means
:> character (char) primitives, that should be:
:>
:> Character.digit(char ch, int radix)
:
:Aside from the object/primitive distinction (I didn't notice that),
:the method you suggest does something completely different than the
ne I suggested. It does the following conversion:
:
: '0' -> 0
: '1' -> 1
: ...
: '9' -> 9
: 'a' -> 10
: 'b' -> 11
: ...
: 'z' -> 35
:
:i.e. the value represented by a character when used as a digit to
:display numbers in a given radix.
:
:My interpretation of his question was how to get the ascii value of
:the character ('a' -> 97 etc) and convert that to octal (141). The
:value of 'a' already is 97 (no conversion necessary), so only the
:conversion to octal is needed. The Character class seems to be lacking
:a toString() that lets you specify radix.
:
:The original post does seem a little ambiguous though, I had to reread
:it several times before posting this...
:
:/gordon
how would I convert character objects to their octal representation
according to the ASCII table?
Your method leads to the assumption that char values are indeed
usable as int values. I know the question pops up in these USENET
forums often about whether such things are possible, and I've been
led to believe that it's "not supposed to work that way" in Java. It
seems that the C roots are showing after all, I guess.
Well the JLS lists char among the integral types (sec 4.2) and the usual
promotion rules apply. One thing you need to watch out for though is sign
extension when using char as int, since char is unsigned.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.