Convert String from ASCII to EBCDIC in Java?

后端 未结 10 1839
北荒
北荒 2020-11-28 10:38

I need to write a \'simple\' util to convert from ASCII to EBCDIC?

The Ascii is coming from Java, Web and going to an AS400. I\'ve had a google around, can\'t seem

10条回答
  •  隐瞒了意图╮
    2020-11-28 11:26

    This is what I've been using.

    public static final int[] ebc2asc = new int[256];
    public static final int[] asc2ebc = new int[256];
    
    static
    {
      byte[] values = new byte[256];
      for (int i = 0; i < 256; i++)
        values[i] = (byte) i;
    
      try
      {
        String s = new String (values, "CP1047");
        char[] chars = s.toCharArray ();
        for (int i = 0; i < 256; i++)
        {
          int val = chars[i];
          ebc2asc[i] = val;
          asc2ebc[val] = i;
        }
      }
      catch (UnsupportedEncodingException e)
      {
        e.printStackTrace ();
      }
    }
    

提交回复
热议问题