Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASCii to character---character to ASCii 1

Status
Not open for further replies.

dendog

Programmer
Jun 28, 2001
53
US
Hey all;
Since some functions in the Character wrapper classes are based in Unicode i was wondering what functions i would have to use to convert a ASCii value into a character and what functions i would use to convert a character into its ASCii value. Thank you in advance.
 
Hi dendog,

You can simply cast bytes to char and vice versa (byte represents character's ASCII value):

char c = '9';
byte b = (byte)c; // Gives you 57, decimal ascii value of 9
char c2 = (char)b; // '9' again
 
What about the code for 'unvisible' characters, say 'ACK' (acknowledgment)or 'ENQ' (inquiry)? How do I get the ASCII code for these characters in C?

It is not possible to write char c = '\ACK' !!!

Suggest a method to get the ASCII value of such characters.

 
Thanks for the link.

The link and some other sites I searched, give the idea about the codes but don't cover the programming aspect (like how to change from one to other specifically for my problem).

May be I could get some info on the 'Tampa Bay Interactive' but that link doesn't work.

Do you have some solution at hand or can you suggest some alternative method?
 
I want to create a Spreadsheet Format file using my C program. The File will be in ASCII-Fixed Length Format File. Can any one give me some idea about this

Thanks in advance for the same

(S. K. Goel)
 
It is possible to specify the encoding that Java will use to handle characters.

Internally everything is handled via 16bit characters, but external java can handle ASCII just as well as Unicode.

We had a similar problem where data passed from a Java program over a socket to a piece of legacy hardware that could only cope with 8 bit characters was recieving it.

Code:
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream(),Charset.forName(US_ACSII)));

This above piece of code meant that all of the characters and strings that went out over the socket from the Java code were ASCII based.


The charsets that Java currently support are -
US-ASCII - Seven-bit ASCII, a.k.a. ISO646-US, a.k.a. the Basic Latin block of the Unicode character set.

ISO-8859-1 - ISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1 UTF-8 Eight-bit UCS Transformation Format.

UTF-16BE - Sixteen-bit UCS Transformation Format, big-endian byte order.

UTF-16LE - Sixteen-bit UCS Transformation Format, little-endian byte order.

UTF-16 - Sixteen-bit UCS Transformation Format, byte order identified by an optional byte-order mark.


Plus Java being Java it is possible to create your own charsets.

Check out the Java Documentation on the classes
Code:
CharsetProvider
and
Code:
Charset
----------------------------------------
There are no onions, only magic
----------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top