如何在java

时间:2016-02-01 02:14:31

标签: java

我一直致力于我的项目,通过遵循MIX计算机的角色(基于56)来创建char值和int值之间的转换。事实证明我通过使用getNumbericVale()方法找到了从char到int值的转换,但我无法找出保留转换。

这是我的代码

        final char c1,c2,c3,c4,c5;

    c1 = 'I';
    c2 = 'F';
    c3 = 'E';
    c4 = 'B';
    c5 = 'A';

    int c1Cal = Character.getNumericValue('I') - Character.getNumericValue('A') + 1;
    int c2Cal = Character.getNumericValue('F') - Character.getNumericValue('A') + 1;
    int c3Cal = Character.getNumericValue('E') - Character.getNumericValue('A') + 1;
    int c4Cal = Character.getNumericValue('B') - Character.getNumericValue('A') + 1;
    int c5Cal = Character.getNumericValue('A') - Character.getNumericValue('A') + 1;

    //encoded

    int b1 = (int) (c5Cal*Math.pow(56, 0));
    int b2 = (int) (c4Cal*Math.pow(56, 1));
    int b3 = (int) (c3Cal*Math.pow(56, 2));
    int b4 = (int) (c2Cal*Math.pow(56, 3));
    int b5 = (int) (c1Cal*Math.pow(56, 4));

    //Decoded number to character






    System.out.println("Original: "+c1+c2+c3+c4+c5);
    System.out.println("Encoded: "+(b1+b2+b3+b4+b5));
    System.out.println("decoded: "+???);

结果必须是' IFEBA'性格再次。分配表提到您需要使用余数来提取最小数字和整数除法以将所有剩余数字向下移动一个位置。

1 个答案:

答案 0 :(得分:0)

尝试对所有int

使用类似的内容
  int a = 4;
  char b = (char) a;