• Post Reply Bookmark Topic Watch Topic
  • New Topic

ECBDIC Conversion  RSS feed

 
J Aronson
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm trying to convert some ASCII [ISO8859-1] bytes to EBCDIC [500]. Research tells me that I should be able to create strings using the EBCDIC encoding and get the bytes converted that way. This isn't working out so well for me. Here's what I'm doing:



My output is

original char: 'H', original byte: 48, converted byte: e7


according to Wikipedia Extended Binary Coded Decimal Interchange Code the converted byte I should be getting for 'H' is c8

Does anybody see what's wrong?
 
Paul Clapham
Sheriff
Posts: 22832
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you did was this:

(1) Convert (encode) a String to bytes using the system default encoding.

(2) Convert (decode) those bytes to a String assuming they were encoded with CP500.

However since they weren't encoded with CP500, you get random data.

Your main problem is that you think you can produce a String which is encoded in some encoding. You can't. All Strings in Java are simply a sequence of Unicode characters. What you can produce, however, is an array of bytes which represents the EBCDIC encoding of a String:

(That's assuming that CP500 is indeed the right encoding to use.)
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . and welcome to the Ranch
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!