• Post Reply Bookmark Topic Watch Topic
  • New Topic

Charset with US-ASCII  RSS feed

 
Rob Chung
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am converting codes from string/integer to bytes and sending the bytes to the other end using SocketChannel.
The code was encoded with Charset. Here's an example where the string/integer is supposed to be converted into aa[]:
byte [] aa = { 0, 0, 0, 0 };
CharsetEncoder encoder;
Charset charset = Charset.forName("US-ASCII");
encoder = charset.newEncoder();
String t = new String(aa);
try {
ByteBuffer b = encoder.encode(CharBuffer.wrap(t));
} catch (Exception e)
{System.out.println("Error!! "+e.getMessage());}
}
This does not work when I tried to convert an integer of 128 (UnmappableCharacterException). It seems to me aa[] = 00000080 but '80' is not a reconized ASCII value.
Anyone has any idea how I can convert 128 with similar form? Thanks in advance!
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I looked it up in my handy dandy IBM extended architecture reference and sure enough, 128 has no related value in ASCII. However you will be pleased to know that it has no related value in EBCDIC either .
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you read this Converter info in the User Guide on the ICU page?
I am still not sure WHAT it is that you are trying to accomplish.
 
Rob Chung
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
These code is part of a big class that was given to me. I was told of the expected result of this class but not explained how this was done in the code and there's not much comment within the code. I am fixing the code as it doesn't work.
Cindy, I shall look into your suggestions. Thanks for all your help.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!