Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Dirk Bruere at NeoPax Newsgroups: comp.lang.java.programmer Subject: Re: char to decimal Date: Thu, 05 May 2011 16:14:06 +0100 Organization: Dirk Bruere at Neopax Lines: 36 Message-ID: <92ft5pFjeiU1@mid.individual.net> References: <92ea64F3avU1@mid.individual.net> Reply-To: dirk.bruere@gmail.com Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net utqONjXSUhUmxpkR2zWItQmdVFVEXI1Na+MzBqhSfCMXFVRUb7 Cancel-Lock: sha1:b9VUOcpz/ja41PG4cSNP3GoakWg= User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 In-Reply-To: Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:3562 On 05/05/2011 02:59, Lew wrote: > 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"! > I need it to match the packet i/f specs designed by somemone else that requires text characters be sent as decimal ascii -- Dirk http://www.neopax.com/technomage/ - My new book - Magick and Technology