2

What is the simplest way to convert HEX value to ebcdic char type in Java

e.g. The example below will return at sign but I would like to get ebcidic equivalent i.e. space char..

String hex = "40"; char c = (char) Integer.parseInt(hex, 16);

vininet
  • 21
  • 1
  • 2

2 Answers2

1

Simples and most efficient solution would probably be to write up a lookup-table yourself, based on for instance http://www.natural-innovations.com/computing/asciiebcdic.html.

Other solutions can be found here.

Community
  • 1
  • 1
aioobe
  • 413,195
  • 112
  • 811
  • 826
1

To convert hex char to ebcdic (example: C1)

byte b[] = {(byte) Integer.parseInt("C1", 16)};
System.out.print(new String(b, "Cp037"));

The result will be A

Maak
  • 4,720
  • 3
  • 28
  • 39