Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail From: Lew Newsgroups: comp.lang.java.programmer Subject: Re: char to decimal Date: Wed, 04 May 2011 21:59:50 -0400 Organization: albasani.net Lines: 30 Message-ID: References: <92ea64F3avU1@mid.individual.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.albasani.net gEmKq3stG4gkNPqmbIIvVPIPELS1UA7lhJgYxBzmTXsYQLve2K7pSLPO2oHfWQoOMcpnsUkCrP2GUl7MsRXXzg== NNTP-Posting-Date: Thu, 5 May 2011 01:58:37 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="0B6rOpMwwaIZjYY9/qQURvoxlCjNU+kb7oxSb1asnbKyDf0J7RgND0DEA3MzB/U2kO32TEhQAvAWtpDT7d2lRMlxw+JXj/YKqf/Qz3qHlAeY97Zvg9GA8y7MbEOebOJ2"; mail-complaints-to="abuse@albasani.net" User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.14) Gecko/20110223 Thunderbird/3.1.8 In-Reply-To: <92ea64F3avU1@mid.individual.net> Cancel-Lock: sha1:T6bgZb7P3ag8shNlXwZ+oGut+DY= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:3531 On 05/04/2011 08:43 PM, Dirk Bruere at NeoPax wrote: > IU need to take a char in UTF-8 and convert it to an ascii [sic] int (decimal) > > eg "a" = 97 > > which is then converted to the string "97" > Is there a simple way to do this? First of all, a 'char' constant in Java is indicated with single quotes, not double quotes. char letter = 'a'; Second of all, 'char' in Java is a numeric type, so conversion to a numeric value is not needed. Third of all, are you absolutely certain you want to convert the 16-bit value of a 'char' to a 7-bit ASCII value? What about code points that require 32 bits to express? How would you convert those to a 7-bit encoding? Finally, are you asking about direct numeric conversions, i.e., to output simply the numeric 16-bit value of the 'char', or are you asking about converting between different text encodings, e.g., between UTF-8 and ASCII? The answer to this question is key, because if you are talking about encodings then the answer is anything but "that easy"! -- Lew Honi soit qui mal y pense. http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg