Reputation: 11
I've been working on my project to create a conversion between char value and int value by following MIX computer's characters(based on base 56). It turned out I'm find with a conversion from char to int value by using getNumbericVale() method, but I could not figure out reserve conversion.
This is my code below
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: "+???);
The result has to be 'IFEBA' character again. The assignment sheet mentions you need to use remainder to extract the least digit and integer division to move all the remaining digits down one place.
Upvotes: 0
Views: 371
Reputation: 8387
Try to use something like this for all your int
:
int a = 4;
char b = (char) a;
Upvotes: 1